在XAML中选择UserControl的子控件
这是一个通用的语法问题。
我有一个USERCONTROL
<UserControl x:Class="UserControlTest.Views.MyControl">
<StackPanel Name="StackPanel1">
<Button Name="Button1" Content="Hello From UserControl XAML"/>
<Button Name="Button2" Content="Hello From UserControl XAML"/>
</StackPanel>
</UserControl>
,并且窗口
<Window xmlns:views="using:UserControlTest.Views"
x:Class="UserControlTest.Views.MainWindow">
<views:MyControl Name="MyControl1"></views:MyControl>
</Window>
有办法从Mainwindow的XAML中选择子元素的属性,就像我在CS中可以做的那样?
因此,基本上我正在寻找这样的 XAML等效:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Get<UserControl>("MyControl1").Get<Button>("Button1").Content = "Hello From Window CS";
}
}
我希望的是与此类似的东西:
<Window xmlns:views="using:UserControlTest.Views"
x:Class="UserControlTest.Views.MainWindow">
<views:MyControl Name="MyControl1">
<views:MyControl ??? Button1> Hello From Window XAML <views:MyControl ??? Button1>
</views:MyControl>
</Window>
这仅是关于从XAML中的外部选择孩子。这不是要设置可以通过绑定和propper类定义实现的值。
This is a general Syntax Question.
I have a UserControl
<UserControl x:Class="UserControlTest.Views.MyControl">
<StackPanel Name="StackPanel1">
<Button Name="Button1" Content="Hello From UserControl XAML"/>
<Button Name="Button2" Content="Hello From UserControl XAML"/>
</StackPanel>
</UserControl>
And the Window
<Window xmlns:views="using:UserControlTest.Views"
x:Class="UserControlTest.Views.MainWindow">
<views:MyControl Name="MyControl1"></views:MyControl>
</Window>
Is there a way to select the properties of the child elements from XAML of the MainWindow like i can do in cs?
So basically im looking for an XAML equivalent of this:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Get<UserControl>("MyControl1").Get<Button>("Button1").Content = "Hello From Window CS";
}
}
What i hope for is something similar to this:
<Window xmlns:views="using:UserControlTest.Views"
x:Class="UserControlTest.Views.MainWindow">
<views:MyControl Name="MyControl1">
<views:MyControl ??? Button1> Hello From Window XAML <views:MyControl ??? Button1>
</views:MyControl>
</Window>
This is only about selecting the child from outside in XAML. This is not about setting a value which can be achieved with bindings and a propper class definition.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定这是否是您要寻找的内容,但是您可以使用样式并选择您感兴趣的控件:
您可以阅读有关选择器此处
Not sure if this is what you are looking for, but you could use styles and select the control you are interested in:
You can read more about selectors here