【问题标题】:Set one property visible at a time in a Grid row in WPF在 WPF 的 Grid 行中设置一次可见的一个属性
【发布时间】:2013-05-17 05:52:34
【问题描述】:

我有一个Grid,它有多行。在我的网格的第一行中,我有一个DataGrid,当我的Tree 被点击时显示一些内容。 如果TreeView 中单击的值没有内容,则应在grid.row=0 中显示NO-CONntent,而不是DataGrid

我该怎么做。我已将Visibility 设置为collapsed 我的TextBox。当没有内容时,我在后面的代码中设置了Visible。 当 TextBox 被放置在任何地方时它工作正常,但不是在 Grid.Row=0.

XAML

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Name="grid" Height="*"/>
        <RowDefinition Name="horzspliter" Height="5"/>
        <RowDefinition Name="detailview" Height="Auto"/>
    </Grid.RowDefinitions>

    <TextBlock Height="23" Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" Name="textBlock1" Text="No-Content" Visibility="Collapsed" Width="500" />

    // Text Block Is not displayed in the Grid.Row="0"
    <my:DataGrid Grid.Row="0" />
</Grid>

Code behind

if (!File.Exists(path))
{               
    this.textBlock1.Visibility = Visibility.Visible;
}
else
{
    this.textBlock1.Visibility = Visibility.Collapsed;
    //Do Datagrid Operations
}

我怎样才能让它在Grid.Row=0 本身中可见并且我的DataGrid Hidden

【问题讨论】:

    标签: wpf datagrid grid visibility


    【解决方案1】:

    网格与您的TextBox 重叠。您可以在显示TextBox 时将网格可见性设置为Collapsed,或在XAML 中使用DataGrid 更改TextBox 的声明顺序,您的TextBox 将呈现在您的DataGrid 之上。

    【讨论】:

      猜你喜欢
      • 2023-03-17
      • 1970-01-01
      • 2011-04-28
      • 2017-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-03
      • 2012-03-08
      相关资源
      最近更新 更多