小编Tob*_*ias的帖子

从UserControl中的Resources中的代码隐藏访问变量

我有以下问题:我想访问XAML资源中定义的这三个变量之一

<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="../../Themes/MainStyle.xaml" />
        </ResourceDictionary.MergedDictionaries>
        <System:Int32 x:Key="maxVal">500</System:Int32>
        <System:Int32 x:Key="minVal">250</System:Int32>
        <System:Int32 x:Key="actualWidth">250</System:Int32>
    </ResourceDictionary>
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)

我想像这样从Codebehind文件访问“ actualWidth”的值:

private void MinMaxGraphicsMessageSink(bool minmax)
{
   actualWidth = minmax ? 900 : 300;
}
Run Code Online (Sandbox Code Playgroud)

但这是行不通的。有人可以帮忙吗?

c# wpf xaml resourcedictionary

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

标签 统计

c# ×1

resourcedictionary ×1

wpf ×1

xaml ×1