我有silverlight应用程序,其中我添加了一个切换按钮以扩展row.at同时我有2个文本框和1个按钮在同一行。我切换按钮工作正常,但当我点击文本框或按钮行得到扩展这应该不会发生。必须在切换按钮上单击才能展开.plz指导我,我错了。 我的切换按钮添加如下 .xaml
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ToggleButton Style="{StaticResource PlusMinusToggleButtonStyle}" Loaded="ToggleButton_Loaded" />
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
和.cs代码如下
private void ToggleButton_Loaded(object sender, RoutedEventArgs e)
{
ToggleButton button = sender as ToggleButton;
DataGridRow row = button.FindAncestor<DataGridRow>(); //Custom Extension
row.SetBinding(DataGridRow.DetailsVisibilityProperty, new System.Windows.Data.Binding()
{
Source = button,
Path = new PropertyPath("IsChecked"),
Converter = new VisibilityConverter(),
Mode = BindingMode.TwoWay
});
}
和接口IValueConverter实现如下
public class VisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if ((bool)value) return Visibility.Visible;
else return Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if ((Visibility)value == Visibility.Visible)
return true;
else return false;
}
}
我需要在convert和ConvertBack检查什么条件。如何检查点击的对象是切换按钮而不是其他按钮
答案 0 :(得分:0)
您可以在ToggleButton_clicked事件中编写为ToggleButton_Loaded事件编写的相同代码,然后您不必检查单击哪个按钮或textBox。
<ToggleButton Style="{StaticResource PlusMinusToggleButtonStyle}" Click="ToggleButton_Clicked" />
.cs代码为
private void ToggleButton_Clicked(object sender, RoutedEventArgs e)
{
ToggleButton button = sender as ToggleButton;
DataGridRow row = button.FindAncestor<DataGridRow>(); //Custom Extension
row.SetBinding(DataGridRow.DetailsVisibilityProperty, new System.Windows.Data.Binding()
{
Source = button,
Path = new PropertyPath("IsChecked"),
Converter = new VisibilityConverter(),
Mode = BindingMode.TwoWay
});
}