XAML WrapPanel inside TreeView - xaml

I have a TreeView displaying items through a Hierarchical Data Template. Now I want to display two properties of an object in the TreeView, as in:
Object1 Name Object1 Src
Object2 Name Object2 Src
Object3 Name Object3 Src
How can I format the output, so that the Src is always aligned on the right side of the TreeViewItem?

The TreeViewItem is not streched to full width by default. You can do this by overriding the default style.
<Style TargetType="TreeViewItem" BasedOn="{StaticResource {x:Type TreeViewItem}}">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>

Related

how to change selected item background based on page

I want to change selected item background color of my GridView based on pages. I define a Color property in each ViewModels, then assign the ViewModel to the view's DataContext. I edit the ItemContainerStyle in app.xaml and want to bind the ViewModel's color property to the selectionbackground, so that the background color of selected item is different in each views, but it doesn't work, I couldn't see the expected color. Anyone can help?
If we apply styles in the app.xaml page they will apply to all our application.
I think you can do this by defining your resources at page level using "UserControl.Resources" in your page.
<UserControl.Resources>
<Style TargetType="...">
...
</Style>
</UserControl.Resources>
You can even set key property in the style and apply to the control like bellow
<UserControl.Resources>
<Style x:Key="my_key" TargetType="...">
....
</Style>
</UserControl.Resources>

Change size of a WatermarkText into a WatermarkTextBox with WinRT XAML Toolkit

I use this lib : http://winrtxamltoolkit.codeplex.com/
I want to specify the FontSize of the WatermarkText, how can I do that ?
Thanks
You can use the Watermark property instead of the WatermarkText one to put anything you want as your watermark - e.g. a TextBlock with any properties you want. You can also use the WatermarkTextStyle property when using WatermarkText and specify the Style to use with the provided watermark TextBlock - something like:
<xc:WatermarkTextBox
WatermarkText="Type something">
<xc:WatermarkTextBox.WatermarkTextStyle>
<Style
TargetType="TextBlock">
<Setter
Property="FontSize"
Value="18" />
...
You can check the sample to see some options here.

how to set a Viewmodel property when a listbox item is selected

I'm creating a spline designer which requires multiple spline parts.
It contains 2 views (2 UserControls).
The left one is an ItemsControl templated as a Canvas displaying the splines to edit.
The splines parts are UserControls as well.
The right one is a simple ListBox used to select a Spline part.
These two item container are bound to the same ObservableCollection in a ViewModel.
For now, I have a dependencyProperty in the SplinePartVM named IsSelected
What I exactly want to achieve is to modify the DependencyProperty of the SplinePartVM when the SelectedItem is set in the ListBox.
for example, i'd like to do something like this:
<Trigger Property="IsSelected" Value="True">
<Setter Property="{Binding IsSelected}"/>
</Trigger>
because a simple
<ListBox IsSelected="{Binding SelectedItem, Path=IsSelected, Mode=TwoWay}"/>
doesn't work.
I'm a bit lost here...
I found it.
I had to set IsSelected in the style of the ListBoxItem to make it work.

Infragistics/XAML - Checking value in a field

I've been working on checking a value in an Infragistics DataProvider Field and if it's a specific value, change it.
<igDP:Field Name="BeginDate" Label="Begin Date">
<igDP:Field.Settings>
<igDP:FieldSettings>
<igDP:FieldSettings.EditorStyle>
<Style TargetType="{x:Type igEditors:XamDateTimeEditor}">
<Style.Triggers>
<DataTrigger Binding="{Binding BeginDate}" Value="01/01/0001">
<Setter Property="Text" Value=" "/>
</DataTrigger>
</Style.Triggers>
</Style>
</igDP:FieldSettings.EditorStyle>
</igDP:FieldSettings>
</igDP:Field.Settings>
</igDP:Field>
The BeginDate value is of type DateTime. I am trying to check it for being DateTime's min value and, if so, I simply want the field to display a blank.
I have tried XamDateTimeEditor as well as XamTextEditor. With DateTimeEditor, nothing happens. With TextEditor, all values are blanked out.
Would appreciate a nudge in the right direction!
You can do this by changing the Template of the editor to be empty when the value is the minimum value for a DateTime. There are a few changes needed to accomplish this.
Change #1, in the style provided the binding is to BeginDate and this binding is invalid because the DataContext is the DataRecord and not the item from the list that you are binding to. If you check the output window you will see errors like the following:
System.Windows.Data Error: 40 : BindingExpression path error: 'BeginDate' property not found on 'object' ''DataRecord' (HashCode=13078478)'. BindingExpression:Path=BeginDate; DataItem='DataRecord' (HashCode=13078478); target element is 'XamDateTimeEditor' (Name=''); target property is 'NoTarget' (type 'Object')
To resolve this, change the binding to be "DataItem.BeginDate" rather than "BeginDate".
Change #2, modify the Setter to set the Template rather than the Text and set it to an empty ConrolTemplate.
The updated Field definition will be:
<igDP:Field Name="BeginDate">
<igDP:Field.Settings>
<igDP:FieldSettings>
<igDP:FieldSettings.EditorStyle>
<Style TargetType="{x:Type igEditors:XamDateTimeEditor}">
<Style.Triggers>
<DataTrigger Binding="{Binding DataItem.DateOfHire}" Value="01/01/0001">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</igDP:FieldSettings.EditorStyle>
</igDP:FieldSettings>
</igDP:Field.Settings>
</igDP:Field>
This solution will still allow you to edit values if editing is enabled for this field in your grid.

Datepicker Watermark

I found this answer in Stackoverflow for Removing Datepicker Watermark.
<Style TargetType="{x:Type toolkit:DatePickerTextBox}">
<Setter Property="Text" Value="Bitte wählen" />
</Style>
is it possible to set above using vb.net code.
Thank you,
Rey.
The one way I can think of to do this is using a resource dictionary.
Create a resource dictionary with that bit of XAML in it and add the dictionary to your resources on Window Initialized. This is a nice way to change styles dynamically in WPF.
In Visual Studio, add a new Resource Dictionary and make it look like this:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
>
<Style TargetType="{x:Type toolkit:DatePickerTextBox}">
<Setter Property="Text" Value="Test" />
</Style>
</ResourceDictionary>
Then in your window add the following to add the resource dictionary to your apps resources:
Private Sub Window1_Initialized(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Initialized
Dim rd As New ResourceDictionary()
rd = CType(Application.LoadComponent(New Uri("Dictionary1.xaml", UriKind.Relative)), ResourceDictionary)
Application.Current.Resources.MergedDictionaries.Clear()
Application.Current.Resources.MergedDictionaries.Add(rd)
End Sub
If you don't want to use styles the only thing that seems to make sense then is to override the default implementation of the DatePicker and implement your own. A good description of how to do that can be found here:
http://www.tanguay.info/web/index.php?pg=codeExamples&id=144