|
I need to add two TextBlocks to each TreeView item, and have them be right-justified in the tree (in other words, butted up against the right side of the tree.
I've tried the following (this is the TreeView xaml), and I get the desired TextBlocks, but the are right next to the TreeViewItem itself.
<TreeView Name="sceneTree"
ItemContainerStyle="{DynamicResource SceneTreeItemStyle}"
PreviewMouseRightButtonDown="OnPreviewMouseRightButtonDown">
<TreeView.Resources>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Border Grid.Column="0" BorderThickness="2,0,0,0" BorderBrush="Transparent"
Background="Transparent" x:Name="PART_ItemBorder" Margin="0"
Padding="1,0,0,0" HorizontalAlignment="Stretch">
<Label Content="{Binding}" />
</Border>
<StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
<TextBlock Text=" ? " FontFamily="Arial" FontWeight="ExtraBlack" Background="Yellow" Foreground="Red" VerticalAlignment="Center" />
<TextBlock Text=" X " FontFamily="Arial" FontWeight="ExtraBlack" Background="Yellow" Foreground="Red" VerticalAlignment="Center" />
</StackPanel>
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</TreeView.Resources>
</TreeView>
The SceneTreeItemStyle looks like this (and the two TextBlock objects are displaying where I want them):
<Style x:Key="SceneTreeItemStyle" TargetType="{x:Type TreeViewItem}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="HorizontalContentAlignment"
Value="{Binding HorizontalContentAlignment,
RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
<Setter Property="VerticalContentAlignment"
Value="{Binding VerticalContentAlignment,
RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
<Setter Property="Padding" Value="1,0,0,0"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisual}"/>
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
<Setter Property="FontWeight" Value="Normal" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TreeViewItem}">
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="19" Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<ToggleButton x:Name="Expander" ClickMode="Press"
IsChecked="{Binding IsExpanded,
RelativeSource={RelativeSource TemplatedParent}}"
Style="{StaticResource ExpandCollapseToggleStyle}"/>
<Border x:Name="Bd"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
Grid.Column="1" Padding="{TemplateBinding Padding}"
SnapsToDevicePixels="true">
<ContentPresenter x:Name="PART_Header" ContentSource="Header"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
<ItemsPresenter x:Name="ItemsHost" Grid.ColumnSpan="3" Grid.Column="1"
Grid.Row="1" HorizontalAlignment="Stretch" />
<StackPanel Orientation="Horizontal" Grid.Column="3" HorizontalAlignment="Right">
<TextBlock Text=" ? " FontFamily="Arial" FontWeight="ExtraBlack"
Background="Yellow" Foreground="Red" VerticalAlignment="Center" />
<TextBlock Text=" X " FontFamily="Arial" FontWeight="ExtraBlack"
Background="Yellow" Foreground="Red" VerticalAlignment="Center" />
</StackPanel>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Can anyone help?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
I'm not quite sure I get your question... but I'm assuming you are getting something like:
<tree view item>? X
and you want something like:
<tree view item> ? X
TreeViewItems don't stretch horizontally by default, so that's why you get the first version above. If you want the 2nd version (i.e. a "multi-column" tree view item), you'd need to stretch the TreeViewItem horizontally and fake the selection rectangle.
You are going to run into a bunch of alignment issues, so I'd suggest finding a real WPF multi-column TreeView control and using that, so items are properly aligned and clipped and thus your ? and X will be aligned properly.
|
|
|
|
|
I am using a list box in WPF. I allowed the users to paste the data to the listbox. I used the following if statement to check if users pressed Ctrl-V:
if (e.Key == Key.V && Keyboard.Modifiers == ModifierKeys.Control){}
But this if statement does not work if users pressed Ctrl and V at the same time. If users pressed the Ctrl and V at the same time, Key will be LeftCtrl and Keyboard.Modifiers will be none.
Thanks.
|
|
|
|
|
Rather than trying to brute force the paste handler, why not use DataObject.AddPastingHandler(MyListBox, OnClipboardPaste); to hook up a paste handler to your listbox?
|
|
|
|
|
It works. Thank you very much, really appreciate it.
|
|
|
|
|
|
Small team, but different preferences for formatting Xaml.
(and one member who can't use the VSCommands 'Format Xaml' option as vSCommands crashes his VS2010)
So if I check out some Xaml, make a small change and reformat it so it looks nice - a Diff shows just about every line as changed - even though it's just splitting most lines up over several lines...
IS there a source compare tool out there that handles this (essentially I guess I am looking for something that does not do a line-by-line compare but a text string compare, and ignores white space including new line/carriage return, tab, and spaces.
Is there something? Or alternatively how do you cope in a multiple dev environment?
|
|
|
|
|
_Maxxx_ wrote: but a text string compare, and ignores white space including new line/carriage return, tab, and spaces.
Just thinking about that made my eyes cross, I once did a csv reader that supported the text qualifier - that was simple compared to this requirement.
I refuse to use 2 spaces for a tab and ALWAYS change it to 2 spaces, in VS SSMS everywhere. I also have the authority to make all the others conform. I don't think I could enforce a xaml layout - I can't make up my mind which layout to use!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: that made my eyes cross,
and there's nothing worse than angry eyes
it shouldn't be THAT big a problem - just have to decide when to give up looking for matching strings and treat the whole thing as one ling text string, rather than a series of lines.
My preference is to use tabs for layout - then each user can just adjust their own tab size for display without the need to change code at all.
|
|
|
|
|
I remember being able to turn off blank line compare in WinMerge[^].
|
|
|
|
|
|
If you follow my sig, you can download a tool called MoXAML PowerToys[^] which contains a handy addin for formatting XAML with a predefined set of rules (and it doesn't crash Visual Studio). I have more details here[^] on what the tool does.
|
|
|
|
|
Ta Pete,
unfortunately because the different devs prefer different layout it means the tool makes every line of Xaml appear to have changed when one does a Diff in TFS - which is what I'm trying to avoid.
|
|
|
|
|
Hi,
In my application I am using silverlight 4.0, Wcf RIA services and entity frame work. Some time it giving me domain service time out error so I want to extend the domain service response time so might be I can overcome from this error.
So how can I reset the domain service tiemout or any other solution to get out fromthis situation.
Thanks in advance.
Saurabh Jain
|
|
|
|
|
You might find it better to put this in the WCF forum[^] as this seems to be more of a WCF thing rather than Silverlight.
|
|
|
|
|
Can we delete downloaded xap files from client machine in silverlight 4.0
|
|
|
|
|
Not unless you have heightened rights on the computer, Silverlight has no access to the file system without the users specific involvement.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Clearing the temporary internet files should ideally remove the xap files.
|
|
|
|
|
Is it possible to create bindings based on lookup values? (I think that's what I'm trying to do)
Say I had a List of items, that I was already binding too, could I use a property of one of those items as a lookup in another list?
I've got the lists defined in my ViewModels ok, and if I want to display the lookup list I've got that working. But I'm not sure how to get other list to relate to the lookup
I *think* a converter might be required, but I'm not sure.
I could *cheat* a put the lookup list in the Model, but that doesn't seem the right approach at all...this is a view only thing.
|
|
|
|
|
cjb110 wrote: I could *cheat* a put the lookup list in the Model, but that doesn't seem the right approach at all...this is a view only thing.
You've almost provided an answer to your own question: The viewmodel you are binding to can have the value being bound and the lookup list(s) being used. That way, when the bound "master" property changes, the view model handles/cascades the update to the dependant lookup list. Here is some psuedocode to try and help explain what I mean:
public class FooViewModel : INotifyPropertChanged
{
string _boundProperty;
public string BoundProperty
{
get
{
return _boundProperty;
}
set
{
if(_boundProperty != value)
{
_boundProperty = value;
NotifyPropertyChanged("BoundProperty");
NotifyPropertyChanged("DependantProperty");
}
}
}
public List<Foo> DependantProperty
{
get
{
return MyMasterListOfFoo.Where(x=> x.Bar ==BoundProperty).ToList()
}
}
}
BoundProperty is the propert that gets changed to kick off the changes and is bound to some control in your XAML. DependantProperty is bound to the control that will be updated when BoundProperty changes
|
|
|
|
|
Ah that makes sense!
In my case I wanted to provide a visual indication that text items where different.
I didn't care about the colour used though, so I originally created a random colour in a collection in the VM and it was that collection I was trying to lookup.
But I realised that as long as the colour was the same for the same string, then the conversion from string to colour had nothing to do with my model or viewmodel.
So I created an IValueConvertor:
public class StringToColorConvertor : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (!(value is string))
throw new ArgumentException("value is not a string");
string text = (string) value;
byte[] data;
using (MD5 md5 = MD5.Create())
data = md5.ComputeHash(Encoding.UTF8.GetBytes(text));
return new SolidColorBrush(Color.FromArgb(150, data[0], data[7], data[15]));
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
If your using similar ish strings you might get colours close together, but for my set of 5 pairs, each colour was different enough to be recognizable.
|
|
|
|
|
Hi All,
I have developed an application in WPF with SQL server as database and the database table contains image data types also.
My data base server is and centralized one and am accessing it via internet thorough sql adapter.
Problem
Now i have problem that it is taking more time to fetch the image data type records and also normal data also taking much time to fetch via internet.
Clarification
1) I have an idea to convert this application to web so that the application server and the database server in the same box will retrive it faster and give the result.
My application is in WPF, the best easy method is to convert it into silver light or wpf browser appliation? if it is wpf browser application can i host it into iis?
2) Or can i have the wpf application as such and change the database hit to the webservices? will webservice respond faster for data fetching also with the image data types?
thanks in advance for your time in helping me pulling out of this crisis.
|
|
|
|
|
A WPF application can be hosted on IIS by making it an xbap (WPF browser based) application[^].
However, in your case, this will still not solve the performance issue you are facing with images.
Optimizing WPF Application Performance [^] might help you try to render images faster.
|
|
|
|
|
Dear Abhinav,
Thanks for your time in replying to my question.
You mentioned that eventhough my application after converted to xbap application it wont work for images.
But my question is, am going to host the database server and the IIS server in the same machine. In that case it should work fine right?
my windows application is working fine for this case.. when my application and the database server in the same machine its working fine.
But i have one doubt. I read in the google that when ever user clicks the xbap , it will internally handles the exe downloads and all.
Which means that everytime the user clicks the link will it downlaod the exe application? and will it run from local machine?
can you please help me to get clarified on this?
that is the case once again its going to be a windows application and will have same image problem?
modified 5-Nov-12 6:13am.
|
|
|
|
|
Hi,
I have few input controls in my ClaimsReport.xaml, based on the user input i have to hit the database fetch records and display those records in UI with header & footer. Along with I have to provide print option to generate the report with header and footer & export to Excel, .csv, .txt formats. Please suggest or share me how to achieve it. Refer the below screenshots.
<a href="C:\Users\sathees_km\Documents\Claims Report.jpg">Window Design</a>
<a href="C:\Users\sathees_km\Documents\Report Data.jpg">Report Data</a>
Regards,
Satheeskumar Manickam
modified 30-Oct-12 6:50am.
|
|
|
|