【问题标题】:Change a value in xaml with code in .cs (C#, Visual Studio 2012) [closed]使用 .cs 中的代码更改 xaml 中的值(C#,Visual Studio 2012)[关闭]
【发布时间】:2013-11-25 08:57:50
【问题描述】:

我在 XAML 中有以下代码:

<ht:BindableTranslateManipulator Direction="1 0 0"  Length="5" Diameter="1" Color="Black" 
                    Value="{Binding Variable}"
                    TargetTransform="{Binding Transform, ElementName=model1}"/>
                    <ht:FileModelVisual3D x:Name="model1" Source="C:\Users\SirBen\Downloads\helixtoolkit\helixtoolkit_27536c46993c\Source\Examples\ExampleBrowser\Cap.3ds"/>

现在我想通过 .cs 中的编码来更改和重复更新“变量”的值。

我该怎么做?没有Variable.value("Value");这么简单的东西吗?

【问题讨论】:

    标签: c# .net wpf visual-studio xaml


    【解决方案1】:

    使用DependencyProperty 并保持绑定不变。我假设它是您要绑定的整数值

    public int Variable
    {
        get { return (int)GetValue(VariableProperty); }
        set { SetValue(VariableProperty, value); }
    }
    
    // Using a DependencyProperty as the backing store for Variable.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty VariableProperty =
        DependencyProperty.Register("Variable", typeof(int), typeof(ownerclass), new PropertyMetadata(0));
    

    在代码隐藏文件中,您可以像操作普通属性一样操作 Variable 的值

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-14
      • 1970-01-01
      • 1970-01-01
      • 2013-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多