You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
3.5 KiB
51 lines
3.5 KiB
<infControls:DemoView x:Class="Samples.Modules.PropertyGrid.Views.BindingToStructs"
|
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
xmlns:infControls="clr-namespace:Samples.Infrastructure.Controls;assembly=Samples.Infrastructure"
|
|
xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
|
|
xmlns:local="clr-namespace:Samples.Modules.PropertyGrid.Views"
|
|
Title="Binding to Structs">
|
|
|
|
<infControls:DemoView.Resources>
|
|
<local:DimensionsConverter x:Key="DimensionsConverter" />
|
|
</infControls:DemoView.Resources>
|
|
<Grid>
|
|
|
|
<Grid.RowDefinitions>
|
|
<RowDefinition Height="Auto" />
|
|
<RowDefinition Height="*"/>
|
|
</Grid.RowDefinitions>
|
|
|
|
<TextBlock Text="When the SelectedObject contains properties of type Struct youmay find that edits performed in the PropertyGrid do not function properly. This is because Structs are passed by value. Meaning that the PropertyGrid receives a copy of the Struct and not a reference. When this happens, the data binding expressions end up binding to and modifying that copy rather than the original values."
|
|
TextWrapping="Wrap" />
|
|
|
|
<StackPanel Grid.Row="1" Margin="10">
|
|
<TextBlock Text="Binding to Structs:" Style="{StaticResource Header}" />
|
|
<TextBlock Text="The solution to this problem is to create a custom editor and provide an IValueConverter to handle the proper conversion of the Struct values." TextWrapping="Wrap" />
|
|
<extToolkit:PropertyGrid x:Name="_propertyGrid" Width="450" Margin="10" >
|
|
<extToolkit:PropertyGrid.EditorDefinitions>
|
|
<extToolkit:EditorDefinition TargetType="{x:Type local:Dimension}">
|
|
<extToolkit:EditorDefinition.EditorTemplate>
|
|
<DataTemplate>
|
|
<Grid Margin="5" >
|
|
<Grid.RowDefinitions>
|
|
<RowDefinition Height="Auto" />
|
|
<RowDefinition Height="Auto" />
|
|
</Grid.RowDefinitions>
|
|
<Grid.ColumnDefinitions>
|
|
<ColumnDefinition Width="Auto" />
|
|
<ColumnDefinition Width="*" />
|
|
</Grid.ColumnDefinitions>
|
|
<TextBlock Text="Height: " />
|
|
<TextBox Grid.Column="1" Text="{Binding Path=Value, Converter={StaticResource DimensionsConverter},ConverterParameter=Height}" />
|
|
<TextBlock Grid.Row="1" Text="Weight: " />
|
|
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Path=Value, Converter={StaticResource DimensionsConverter},ConverterParameter=Weight}" />
|
|
</Grid>
|
|
</DataTemplate>
|
|
</extToolkit:EditorDefinition.EditorTemplate>
|
|
</extToolkit:EditorDefinition>
|
|
</extToolkit:PropertyGrid.EditorDefinitions>
|
|
</extToolkit:PropertyGrid>
|
|
</StackPanel>
|
|
</Grid>
|
|
</infControls:DemoView>
|
|
|