0

我已经在 Datagrid 中定义了一个包含三行和 9 列的初始表。仅当我选择一行然后按下我在功能区选项卡中定义的另一个按钮之后,我的按钮才可见,现在按钮应该是可见的。到目前为止一切正常,但问题是在保存我的表格后,将其关闭并再次打开表格,按钮不再存在。我根据 DataGridCell.IsSelected 设置了 Visibility,它也是一个 BooleanToVisibilityConverter,用于将布尔值转换为 Visibility。谁能帮忙!

XAML:

<DataGrid.Resources>
   <BooleanToVisibilityConverter x:Key="BoolToVisConverter" />
</DataGrid.Resources>
<DataGridTemplateColumn x:Name="subgraphtyp" Header="H." Width="50">
   <DataGridTemplateColumn.CellTemplate>
     <DataTemplate>
       <Button Name="btnTable" Visibility="{Binding Path=Hinterlegung, Converter=  
               {StaticResource BoolToVisConverter}}"  Height="20" Width="25" 
               Click="Button_Table_Click">
         <Image Height="16" Source="Subgraph.png" Stretch="Fill" Width="16"/>
       </Button>
     </DataTemplate>
   </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

C#: public bool Hinterlegung { get; 放; }

private void Button_StartTableModus(object sender, RoutedEventArgs e)
{
  if (DataGrid1.SelectedItem != null && tabItem1.IsSelected)
  {
    TableDataRowStringItem item = (TableDataRowStringItem)DataGrid1.CurrentItem;
    string wert = item.ObjectType;
    string rowName = item.Name;
    if (wert == "Function" || wert == "Process")
    {
      item.Hinterlegung = true;
      if (!tabControl.Items.Contains(tabItem2))
      {
        tabControl.Items.Add(tabItem2);
        tabItem2.Focus();
        tabItem2.IsSelected = true;
        tabItem2.Header = rowName;
        TableTab.Visibility = Visibility.Visible;
        openTabs++;
        DataGrid2.IsReadOnly = false;

        starting_Table_Mod_at_start2V();
      }
    }
  }
}

//this my initial Table
private ObservableCollection<TableDataRowStringItem> tableobject = new      
ObservableCollection<TableDataRowStringItem>();

private void starting_Table_Mod_at_start2V()
{
  List<TableDataRowStringItem> rowstringList = new List<TableDataRowStringItem>();
  TableDataRowStringItem item = new TableDataRowStringItem();
  item.RowNumber = 1; item.saveFlag = true; item.ObjectType = "E"; item.Name = "E"; 
  item.PredecessorRowNumber = "0"; rowstringList.Add(item);
  item = new TableDataRowStringItem();
  item.RowNumber = 2; item.ObjectType = "Function"; item.Name = "Function";       
  item.PredecessorRowNumber = "1"; rowstringList.Add(item);
  item = new TableDataRowStringItem();
  item.RowNumber = 3; item.ObjectType = "E"; item.Name = "E";   
  item.PredecessorRowNumber = "2"; rowstringList.Add(item);


  for (int i = 0; i < rowstringList.Count; i++)
  {
    tableobject.Add(rowstringList[i]); 
  }
  DataGrid2.ItemsSource = tableobject;
}
4

1 回答 1

0

您的按钮的可见性绑定到您的 Hinterlegung 变量,该变量的默认值为 false。因此,据我所知,您在此方法中将其更改为 true - Button_StartTableModus。但是,当您重新初始化时,该值将恢复为 false,因此您需要将其设置为 true。

于 2012-09-13T14:17:05.043 回答