2016-08-05 151 views
0

私はタイトル付きのToggleボタンを持っています。私はToggleSwitch.xaml UserControlを作成して、複数のページで使用できるようにしました。すべてが完璧に進んでいます。WPF usercontrolからTextBlockコントロールを非表示/非表示にするにはどうすればいいですか?

しかし、1ページでは、ユーザーが状態を変更できるようにDataGridの切り替えボタンを表示する必要がありますが、使用時にToggleSwitch UserControl TextBoxにはデザインが非常に悪くなるスペースが必要です。

テキストボックスではなく、DataGridにToggleSwitchボタンを表示したいだけです。

私は自分のデザインに影響しないようにTextBoxを非表示にしたいと思います。

ご協力いただきありがとうございます。下記のコードをご覧ください。

<StackPanel Orientation="Horizontal" x:Name="LayoutRoot" Margin="0,0,-23,0"> 
    <ToggleButton Name="toggleButton" VerticalAlignment="Center" Click="ToggleButton_OnClick" IsChecked="{Binding Path=StateChecked}" Cursor="Hand" Style="{DynamicResource AnimatedSwitch}" Height="13" Width="23" Margin="0,0,0,0" /> 
    <TextBlock Name="tbText" Text="{Binding Path=ControlText}" VerticalAlignment="Center" Width="279" Margin="15,8,0,7"></TextBlock> 
</StackPanel> 
+0

あなたのユーザーコントロールにブール値を追加して、それがマークされているとテキストボックスを非表示にすることがあります –

+0

もっと詳しい@DarkTemplarを教えてください。 –

+0

私はあなたのユーザーコントロールのxamlを見る必要があり、私は例を書いています。 –

答えて

0

Dependency Propertiesを使用してこれを達成できます。テキストボックスの可視性を、ユーザーコントロールの依存プロパティにバインドします。

まず、このように依存関係プロパティを作成します。

public Visibility TextBlockVisibilityProperty 
{ 
    get { return (Visibility)GetValue(TextBlockVisibilityPropertyProperty); } 
    set { SetValue(TextBlockVisibilityPropertyProperty, value); } 
} 

// Using a DependencyProperty as the backing store for TextBlockVisibilityProperty. This enables animation, styling, binding, etc... 
public static readonly DependencyProperty TextBlockVisibilityPropertyProperty = 
    DependencyProperty.Register("TextBlockVisibilityProperty", typeof(Visibility), typeof(MaintenancePage), new PropertyMetadata(0)); 

を次にXAMLで

<StackPanel Orientation="Horizontal" x:Name="LayoutRoot" Margin="0,0,-23,0"> 
    <ToggleButton Name="toggleButton" VerticalAlignment="Center" Click="ToggleButton_OnClick" IsChecked="{Binding Path=StateChecked}" Cursor="Hand" Style="{DynamicResource AnimatedSwitch}" Height="13" Width="23" Margin="0,0,0,0" /> 
    <TextBlock Name="tbText" Text="{Binding Path=ControlText}" VerticalAlignment="Center" Width="279" Margin="15,8,0,7" Visibility="{Binding TextBlockVisibilityProperty}"></TextBlock> 
</StackPanel> 

以下のようなtextblock視界にプロパティをバインド今XAMLでコントロールを再利用する際に定義しながら、TextBlockVisibilityPropertyを設定必要に応じてコントロール。これにより、textblockが非表示になります。

関連する問題