【发布时间】:2014-07-16 00:07:48
【问题描述】:
我的 XAML 引用了以下类。这个类有一堆属于按钮的附加属性和行为,所以它在 UI 方面。
其中一些行为设置了 current_cell_match 并且这些行为中的每一个都有自己的类,这就是为什么我将它放在一个静态类中以便可以共享。
public static class SearchVariables
{
public static DataGridCellInfo current_cell_match;
public static void setCurrentCell(Object dgi, DataGridColumn dgc, string property_name)
{
current_cell_property = property_name;
if (property_name == null)
current_cell_match = new DataGridCellInfo();
else
current_cell_match = new DataGridCellInfo(dgi, dgc);
}
}
我不确定 current_cell_match 应该是成员、属性还是附加属性。我真的不需要将它用作任何 UI 控件上的属性,所以我正在考虑前两个中的一个。
我会将它与 MultiBinding 转换器一起使用,所以我需要知道它的值何时发生变化。所以我倾向于使用 PropertyChangedEventHandler 的属性。但是静态类没有实例,所以这不起作用,没有'this'。
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
这是我最后要使用的多重绑定:
<Setter Property="helpers:SearchBehaviours.IsTextMatchFocused">
<Setter.Value>
<MultiBinding Converter="{StaticResource SelectedSearchValueConverter}" FallbackValue="False">
<Binding Path="(helpers:SearchBehaviours.IsFindPopupOpen)" RelativeSource="{RelativeSource Self}"/>
<Binding Source="{x:Static helpers:SearchVariables.current_cell_match}"/>
</MultiBinding>
</Setter.Value>
</Setter>
有人可以帮我构建 current_cell_match 吗?
【问题讨论】:
标签: c# wpf properties dependency-properties