gpt4 book ai didi

c# - WPF 绑定(bind) RelativeSource

转载 作者:太空宇宙 更新时间:2023-11-03 20:21:42 25 4
gpt4 key购买 nike

只是在这里做一个小测试。这两个文本框中只有第一个显示值“123”。为什么不是第二个?

<Window x:Class="Test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
Title="MainWindow" Height="350" Width="525">
<StackPanel Width="123" x:Name="Panel1">
<TextBox Text="{Binding ElementName=Panel1, Path=Width, diag:PresentationTraceSources.TraceLevel=High}"></TextBox>
<TextBox Text="{Binding Source={RelativeSource AncestorType={x:Type StackPanel}}, Path=Width, diag:PresentationTraceSources.TraceLevel=High}"></TextBox>
</StackPanel>

最佳答案

RelativeSource代替Source,像这样:

<TextBox Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type StackPanel}}, Path=Width, diag:PresentationTraceSources.TraceLevel=High}"></TextBox>

关于c# - WPF 绑定(bind) RelativeSource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13077703/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com