簡體   English   中英

如何將一個控件的屬性綁定到另一個控件?

[英]How to bind property of one control to another?

我有一個WPF控件(ControlA),它引用了另一個控件(ControlB),如下所示:

<Grid>
    <controls:ControlB x:Name="ControlB"  />         
    <my:DataGrid 
        x:Name="dataGridBackup" 
        ItemsSource="{Binding}" 
        AutoGenerateColumns="False" >
        <my:DataGrid.Columns>
            <my:DataGridCheckBoxColumn 
                Header="Connectable" 
                Binding="{Binding Connectable}"  />
        </my:DataGrid.Columns>
    </my:DataGrid>
</Grid>

現在在ControlB中,我有一個按鈕,我想將IsEnabled屬性綁定到controlA上我的網格的Connectable列。

當我在同一頁面上擁有控件時,而在沒有上述場景的情況下,我可以使它工作。 我嘗試過

<Button 
    IsEnabled="{Binding ElementName=dataGridBackup, Path=SelectedItem.Connectable}">
</Button>

ControlB內部的按鈕沒有正常的方法來知道ControlB外部的內容。 一個可能的解決方案是布爾依賴屬性添加到ControlBIsConnectable 在控件ControlA XAML中,像以前一樣,將屬性與具有path的dataGridBackup綁定。 在控件ControlB XAML中,將按鈕的IsEnabled屬性綁定到ControlB IsConnectable

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM