Release WPF を使用して (もちろんサポートしています)DataGrid
のプロパティにバインドしようとしています。をof 型(Dr.WPF から継承される)の型にバインドしていますが、 のプロパティにバインドしたいと考えています。CellViewModel
INotifyPropertyChanged
DataGrid
ItemsSource
ObservableCollection
RowViewModel
ObservableDictonary
CellViewModel
CellViewModel
たとえば、次の例では、ブール値のDatagridCell.FontStyle
プロパティに基づいてプロパティの状態を変更しようとしています (イタリック体の場合)。CellViewModel.IsLocked
IsLocked
最初に、関連する CellViewModel オブジェクトを XAML で公開します。
<DataGrid.Resources>
<cv:RowColumnToCellConverter x:Key="RowColumnToCellConverter"/>
<MultiBinding x:Key="CellViewModel" Converter="{StaticResource RowColumnToCellConverter}">
<Binding />
<Binding RelativeSource="{x:Static RelativeSource.Self}" Path="Column" />
</MultiBinding>
</DataGrid.Resources>
RowColumnToCellConverter は
public class RowColumnToCellConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
RowViewModel<string,CellViewModel> row = values[0] as RowViewModel<string,CellViewModel>;
string column = (values[1] as DataGridColumn).SortMemberPath;
string col = column.Substring(1, column.Length - 2);
return row[col];
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
次にDataTrigger
、XAML でを作成します。
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<DataTrigger Value="True" >
<DataTrigger.Binding >
<Binding Path="isLocked" Source="{StaticResource CellViewModel}" />
</DataTrigger.Binding>
<Setter Property="FontStyle" Value="Italic"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
これは機能しませんが、私がやりたいことの例です。うまくいけば、そう遠くないでしょう。確かに、MultiBinding
はここで設定されることはありません (Converter
はデバッグでチェックと呼ばれることがないため)。
他の場所では、MultiBinding/MultiConverter
(この投稿ではエラーが発生しなかったことを願っていますが)(上記のように StaticResource としてではなく)の一部として機能DataTrigger/MultiTrigger
しますが、それは自分自身にバインドされていないオブジェクト。
つまり、返されるオブジェクトがrow[col].Islockedであるコンバーターのバリアントを持つことができますが、IslockedプロパティはPropertyChange通知に登録されていません。
MultiBind がオブジェクトを返すまで、3 番目のバインド ステートメント{Bind Path=IsLocked}が参照するIsLocked
ものがないため、元の MultiBind の BindingCollection の 3 番目のバインド ステートメントとしてプロパティを追加することはできません(または追加できますか?)。 .
そのため、オブジェクトではなく Binding オブジェクトのみを受け入れるMultiBinding
ため、機能しない次のようなネストを試みました。BindingCollection
MultBinding
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<DataTrigger>
<DataTrigger.Binding>
<MultiBinding>
<MultiBinding Converter="{StaticResource RowColumnToCellConverter}">
<Binding />
<Binding RelativeSource="{x:Static RelativeSource.Self}" Path="Column" />
</MultiBinding>
<Binding Path="IsLocked"/>
</MultiBinding>
</DataTrigger.Binding>
<Setter Property="FontStyle" Value="Italic"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
私の試みた解決策が遠く離れていても、私の問題が上記から明確になることを願っています。それで、私は何が欠けていますか?(私は数週間しか WPF/MVVM を使用しておらず、これは DataGrid を操作するための非常に基本的な要件であるため、おそらく多くの場合、答えが恥ずかしいほど単純であることを願っています)。