点击按钮后,我收到此错误。
http://cid-3dbfac44f49def30.skydrive.live.com/self.aspx/New%20album/error.JPG
这是我的代码
<sdk:DataGrid MinHeight="100" x:Name="dgCounty" AutoGenerateColumns="False"
VerticalAlignment="Top" IsReadOnly="True" Margin="5,5,5,0"
RowDetailsVisibilityChanged="dgCounty_RowDetailsVisibilityChanged"
RowDetailsVisibilityMode="VisibleWhenSelected">
<sdk:DataGrid.Columns>
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="+" Click="Button_Click"></Button>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
<sdk:DataGridTextColumn Header="Countryname" Width="100"
Binding="{Binding Region Name}" CanUserReorder="False"/>
<sdk:DataGridTextColumn Header="Populution" Width="80"
Binding="{Binding Number Of People}" CanUserReorder="False"/>
</sdk:DataGrid.Columns>
<sdk:DataGrid.RowDetailsTemplate>
<DataTemplate>
<sdk:DataGrid x:Name="dgrdRowDetail" Width="400" AutoGenerateColumns="False"
HorizontalAlignment="Center" IsReadOnly="True" Grid.Row="1">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Header="county" Binding="{Binding CompanyName}" />
<sdk:DataGridTextColumn Header="Number Of People" Binding="{Binding CompanyID}"/>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
</DataTemplate>
</sdk:DataGrid.RowDetailsTemplate>
</sdk:DataGrid>
代码: -
private void Button_Click(object sender, RoutedEventArgs e)
{
Button btnExpandCollapse = sender as Button;
var Row = DataGridRow.GetRowContainingElement(sender as FrameworkElement);
if (Row.DetailsVisibility == Visibility.Collapsed)
{
Row.DetailsVisibility = Visibility.Visible;
}
else
{
Row.DetailsVisibility = Visibility.Collapsed;
}
if (btnExpandCollapse.Content.ToString() == "+")
{
btnExpandCollapse.Content = "-";
}
else if (btnExpandCollapse.Content.ToString() == "-")
{
btnExpandCollapse.Content = "+";
}
}
void dtg_RowDetailsVisibilityChanged(object sender, DataGridRowDetailsEventArgs e)
{
DataGrid RowDetails = e.DetailsElement as DataGrid
if(RowDetails.YourDesiciveFlag = true)
{
}
else
{
}
}
}
过去3天处理此问题 任何想法如何解决这个问题。只是对这个问题发疯了。 用于silverlight数据网格中的扩展/ collpase。
如果有人能为我提供任何可以解决我问题的代码,请告诉我。
提前谢谢 王子答案 0 :(得分:0)
从代码的外观来看,你正在尝试做我在这里展示的内容:
http://gallery.expression.microsoft.com/en-us/ToggleRowDetail
希望代码示例(行为)可以帮助您。 迈克尔