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.
69 lines
3.9 KiB
69 lines
3.9 KiB
<!--*********************************************************************
|
|
|
|
Extended WPF Toolkit
|
|
|
|
Copyright (C) 2010-2012 Xceed Software Inc.
|
|
|
|
This program is provided to you under the terms of the Microsoft Reciprocal
|
|
License (Ms-RL) as published at http://wpftoolkit.codeplex.com/license
|
|
|
|
This program can be provided to you by Xceed Software Inc. under a
|
|
proprietary commercial license agreement for use in non-Open Source
|
|
projects. The commercial version of Extended WPF Toolkit also includes
|
|
priority technical support, commercial updates, and many additional
|
|
useful WPF controls if you license Xceed Business Suite for WPF.
|
|
|
|
Visit http://xceed.com and follow @datagrid on Twitter.
|
|
|
|
********************************************************************-->
|
|
<sample: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:sample="clr-namespace:Samples.Infrastructure.Controls;assembly=Samples.Infrastructure"
|
|
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
|
|
xmlns:local="clr-namespace:Samples.Modules.PropertyGrid.Views"
|
|
Title="Binding to Structs">
|
|
|
|
<sample:DemoView.Resources>
|
|
<local:DimensionsConverter x:Key="DimensionsConverter" />
|
|
</sample: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" />
|
|
<xctk:PropertyGrid x:Name="_propertyGrid" Width="450" Margin="10">
|
|
<xctk:PropertyGrid.EditorDefinitions>
|
|
<xctk:EditorDefinition TargetType="{x:Type local:Dimension}">
|
|
<xctk: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>
|
|
</xctk:EditorDefinition.EditorTemplate>
|
|
</xctk:EditorDefinition>
|
|
</xctk:PropertyGrid.EditorDefinitions>
|
|
</xctk:PropertyGrid>
|
|
</StackPanel>
|
|
</Grid>
|
|
</sample:DemoView>
|
|
|