0

私は可視性プロパティを依存関係プロパティにバインドする wpf と xaml を使用していますが、親オブジェクトがバインドを折りたたむと、その理由がわかりません。親が折りたたまれて再び表示されるようになった後にコードでバインディングを再作成すると、プロセスは機能しますが、それは醜く、バインディングの目的を無効にします。問題を再現する小さな wpf プロジェクトを次に示します。

<Window x:Class="RibbonExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
        Title="MainWindow" Height="350" Width="525" KeyDown="Window_KeyDown" KeyUp="Window_KeyUp">
    <Grid>

        <r:Ribbon Grid.Row="0" x:Name="xRibbon" Title="Ribbon Example">
            <r:RibbonTab x:Name="View" Header="Tab" IsSelected="True">
                <r:RibbonGroup Header="Visible">
                    <r:RibbonTextBox x:Name="xButton" Text="Visible Text" />
                </r:RibbonGroup>

                <r:RibbonGroup Header="Invisible" Visibility="{Binding VisibilityDependancy}">
                    <r:RibbonTextBox x:Name="xButton2" Text="{Binding VisibilityDependancy}" />
                </r:RibbonGroup>
            </r:RibbonTab>
        </r:Ribbon>
    </Grid>
</Window>

とコードビハインド。

using System.Windows;
using System.Windows.Input;

namespace RibbonExample
{
    public partial class MainWindow : Window
    {
        public static readonly DependencyProperty VisibilityDependancyProperty =
            DependencyProperty.Register("VisibilityDependancy", typeof(Visibility), typeof(MainWindow), new PropertyMetadata(Visibility.Collapsed));

        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;
        }

        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            SetValue(VisibilityDependancyProperty, Visibility.Visible);
        }

        private void Window_KeyUp(object sender, KeyEventArgs e)
        {
            SetValue(VisibilityDependancyProperty, Visibility.Collapsed);
        }
    }
}

ウィンドウの単純なフォーカスを再現するには、キーを押すと、折りたたまれた RibbonGroup が表示され、離すと非表示になります。タブ ヘッダー "Tab" をダブルクリックしてリボンを折りたたんだ後、元に戻すと、バインドが機能しなくなり、RibbonGroup の可視性は、リボンを折りたたむ前の状態のままになります。

興味深いことに、IsEnabled を実行して true または false に設定しても、リボンの背後にある可視性をバインドしている場合にのみ、バインディングは壊れません。

ありがとう

4

1 に答える 1