私はグリッドを持っています。 私の最終目標は、行が隠れている間にテキストボックスにテキストを設定する方法を見つけることです。テキストボックスのサイズがフォントサイズより小さい場合、wpfがテキストをテキストボックスに設定できない問題が発生することがあります。これは私がこれまで持っているものです。XAML C#グリッド行を非表示
XAML:
Grid>
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="100"/>
</Grid.RowDefinitions>
<Button x:Name="Button1"
Grid.Row="2"
Grid.Column="1"
Width="100"
Height="50"
Click="OnClick"
Content="Hide Middle Row"/>
<Grid x:Name="AddressBar" Grid.Row="1" Grid.Column="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="Block1"
FontSize="16"
Grid.ColumnSpan="3"
HorizontalAlignment="Center"
TextAlignment="Center"/>
</Grid>
</Grid>
のC#:
namespace rowCollapseTest
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void OnClick(object sender, RoutedEventArgs e)
{
AddressBar.RowDefinitions(1).Height = new GridLength(0);
AddressBar.Visibility = Visibility.Collapsed;
Block1.Text = "This is a test";
}
}
}
私が読んだものから、これは動作するはずです。ただし、 "RowDefinitions(1)"に関するエラーが表示されます。 "非呼び出し可能なメンバー 'Grid.RowDefinitions'をメソッドのように使用することはできません。何か案は?
ありがとうございます!
ああ、どのように私はそれをキャッチしませんでした!残念ながら、私は括弧を使用して範囲外のエラーを取得します。私はこれを次のように書くことができます: AddressBar.Height = new GridLength(0); このシナリオでは、次のエラーを受け取りました。暗黙的に型System.Window.GridLengthを「double」に変換できません。 – user5890660
@ user5890660ああ、AddressBarにはRowDefinitionsがまったくありません。他のグリッドには行定義があり、AddressBarには列定義のみがあります。 –
@ user5890660高さはGridLength値ではなく、単なる2倍です。 Visible.CollapsedをVisibilityプロパティに代入するのは良いことです。 –