0

いくつかのラベルを持つデータ テンプレートがあります。構成設定に応じて、実行時にいくつかのラベルを非表示にしたいと考えています。

ラベルの可視性をプロパティにバインドしましたが、プロパティが False であってもラベルが非表示になりません。

以下は私のxamlです

<Label x:Name="lblWashingMachineName" Content="{x:Static Resources:Translations.MainWindow_WashingMachineName}"
                            Grid.Row="6" Grid.Column="2" Style="{StaticResource styleLabelBig}" Visibility="{Binding Path=ShowLabels}"></Label>

財産

    public bool ShowLabels
    {
        get
        {
            return _showLabels;
        }
        private set
        {
            _showLabels = value;
            OnPropertyChanged("ShowLabels");
        }
    }

コンストラクターでのプロパティの設定

    public DisplayScopeRecord()
    {
        ShowLabels = !(AppContext.Instance.DicomizerEnabled);
    }
4

3 に答える 3

0

Label のスタイルを上書きし、 ShowLabelsプロパティの値にデータトリガーを設定する必要があります。

<Label x:Name="lblWashingMachineName" Content="{x:Static Resources:Translations.MainWindow_WashingMachineName}" Grid.Row="6" Grid.Column="2">
    <Label.Style>
        <Style BasedOn="{StaticResource styleLabelBig}" TargetType="{x:Type Label}">
            <Setter Property="Visibility" Value="Visible" />
                <Style.Triggers>
                     <DataTrigger Binding="{Binding Path=ShowLabels}" Value="False">
                          <Setter Property="Visibility" Value="Collapsed" />
                     </DataTrigger>
                </Style.Triggers>
         </Style>
    </Label.Style>
</Label>
于 2013-06-19T07:35:06.757 に答える
0

私のプロパティは、それが機能するために可視性タイプである必要があります。

財産

    public Visibility ShowLabels
    {
        get
        {
            return _showLabels;
        }
        private set
        {
            _showLabels = value;
            OnPropertyChanged("ShowLabels");
        }
    }

コンストラクタ

    public DisplayScopeRecord()
    {
        if (AppContext.Instance.DicomizerEnabled)
        {
            ShowLabels = Visibility.Hidden;
        }
    }
于 2013-06-19T03:09:10.770 に答える