Eri*_*rik 0 controls properties windows-phone windows-phone-8
所以我正在创建这个应用程序,我已经创建了自己的用户控件,并且每个控件都有一些内容将使用来自Web的信息进行更新,但我不知道如何添加属性.就像那个特定控件的名字一样.比如控件中存储的高度设置在哪里?在代码中?像这样
mycontrol:
String nameofthiscontrol = "control";
Run Code Online (Sandbox Code Playgroud)
和主要代码:
mycontrol mycontrol = new mycontrol();
mycontrol.nameofthiscontrol = "control1";
Run Code Online (Sandbox Code Playgroud)
它是如何工作的?我真的需要一些指导,请帮忙!提前致谢!
如果您正在谈论UserControl,它将具有所有控件共有的一些基本属性(如宽度,高度,背景等).您可以在UserControl中添加类似于在其他任何位置添加的属性.
public partial class MyControl : UserControl
{
public MyControl()
{
InitializeComponent();
}
//simple property
public DesiredType PropertyName { get; set; }
//dependancy property
public DesiredType MyProperty
{
get { return (DesiredType)GetValue(MyPropertyProperty); }
set { SetValue(MyPropertyProperty, value); }
}
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MyPropertyProperty =
DependencyProperty.Register("MyProperty", typeof(DesiredType), typeof(ownerclass), new PropertyMetadata(0));
}
Run Code Online (Sandbox Code Playgroud)
两者都很有用(并且必须是公共的),但DependencyProperty更适合MVVM中的绑定.
| 归档时间: |
|
| 查看次数: |
953 次 |
| 最近记录: |