Datagrid row expand on row click in silverlight
i have silverlight application in which i have added one toggle button to expand row.at same time i have 2 textbox and 1 button on same row.my toggle button is working fine but when i click on textbox or button rows get expanded which should not be happen.Row must be expand on toggle button click only.plz guide me whr i am wrong. my toggle button is added like below .xaml
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ToggleButton Style="{StaticResource PlusMinusToggleButtonStyle}" Loaded="ToggleButton_Loaded" />
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
and .cs code is as below
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
});
}
and interface IValueConverter is implemented as below
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;
}
}
开发者_如何学JAVA
what condition i need to check at convert and ConvertBack.or how i can check clicked object is toggle button and not the other button
You can write the same code which you have written for ToggleButton_Loaded event in the ToggleButton_clicked event then you don't have to check for which button or textBox is clicked.
<ToggleButton Style="{StaticResource PlusMinusToggleButtonStyle}" Click="ToggleButton_Clicked" />
And .cs code as
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
});
}
精彩评论