相关疑难解决方法(0)

WPF:XAML属性声明没有通过Setters设置?

我有一个WPF应用程序,我在代码隐藏中使用依赖属性,我想通过XAML声明设置.

例如

<l:SelectControl StateType="A" Text="Hello"/>
Run Code Online (Sandbox Code Playgroud)

所以在这个例子中我有一个UserControl被调用的SelectControl,它有一个属性StateType,在它的setter中操作一些其他的属性.

为了帮助说明问题,我Text在示例中调用了另一个属性,继续阅读,我将进一步解释.

Codebehind摘录......

public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(String), typeof(SelectControl));

public String Text
{
  get { return (String)GetValue(TextProperty); }
  set { SetValue(TextProperty, value); }
}

public static readonly DependencyProperty StateTypeProperty = DependencyProperty.Register("StateType", typeof(String), typeof(SelectControl));

public String StateType
{
  get { return (String)GetValue(StateTypeProperty) }
  set
    {
      switch (value)
      {
        case "A":
          AnotherPropertyBoolean = true;
          break;
        case "B":
          AnotherPropertyBoolean = false;
          break;
       default:
         // this is only …
Run Code Online (Sandbox Code Playgroud)

wpf setter xaml dependency-properties

5
推荐指数
1
解决办法
2805
查看次数

标签 统计

dependency-properties ×1

setter ×1

wpf ×1

xaml ×1