作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设我们有这样的控制:
public partial class MyUserControl : UserControl
{
public MyUserControl() {
InitializeComponent();
}
public string Foo { get; set; }
}
如何在 MyUserControl.xaml 中以声明方式设置“Foo”属性值?
<UserControl x:Class="Test.MyUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- Looking for some thing like this -->
<Foo>Hola</Foo>
</UserControl>
更清楚一点:如何在 XAML 中为代码隐藏中定义的属性设置值。
最佳答案
我过去发现,您可以使用样式从 xaml 设置 UserControl 上的属性,而无需继承。试试这样的:
<UserControl x:Class="Test.MyUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:c="clr-namespace:Test.MyUserControl" >
<UserControl.Style>
<Style>
<Setter Property="c:MyUserControl.Foo" Value="Hola" />
</Style>
</UserControl.Style>
</UserControl>
关于wpf - 在 MyUserControl.xaml 中以声明方式设置 MyUserControl 的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/658045/
假设我们有这样的控制: public partial class MyUserControl : UserControl { public MyUserControl() {
我有一个问题(显然是问题:) 我有一个项目-- MyProject...因此项目的其余部分使用任何类的默认值作为命名空间“MyProject”...没问题。 在我的项目中,我创建了一个自定义用户控件,
我在 MS 的 Blend 中创建了一个用户控件库,用于 WPF C# 项目。这是我第一次尝试使用 Blend 创建用户控件,但我在实现它时遇到了问题。 我遇到的问题是我的 ComboBox。当我转到
这个问题在这里已经有了答案: 关闭10 年前。 Possible Duplicate: Inheriting from a UserControl in WPF 我正在尝试创建一个 WPF 用户控件
我是一名优秀的程序员,十分优秀!