【问题标题】:Binding TextBlock foreground to Global.cs variable in xaml将 TextBlock 前景绑定到 xaml 中的 Global.cs 变量
【发布时间】:2012-07-25 10:31:06
【问题描述】:

我一直在网上搜寻类似的问题,但找不到任何可以解决我问题的方法。

我有一个包含全局变量的静态类,其中一些是我希望能够在我的 xaml 控件中绑定的颜色变量,这样我只需更改一个变量即可更改批次(全局变量的原因) .

类命名空间是MyApp.Assets.Resources,类名称是Global(.cs)。 在我的课堂上,我有名为DEFAULTCOLOROKCOLORALARMCOLOR 的变量。

我的xml:

<UserControl
    <!-- ... -->
    xmlns:custom="clr-namespace:InspectionDB.Assets.Resources"
>
    <UserControl.Resources>
        <custom:Global x:Name="global"/> <!-- THIS GIVES AN ERROR SEE BELOW-->

        <common:HierarchicalDataTemplate x:Key="Level1" ItemsSource="{Binding Path=Children}">
            <StackPanel Orientation="Horizontal">
                <Image Source="{Binding Type, Converter={StaticResource localTreeImgConverter}}"/>
                <TextBlock {Binding...} />
                <StackPanel Orientation="Horizontal" Visibility="{Binding Type, Converter={StaticResource localStatusVisibilityConverter}}">
                    <TextBlock Margin="5,0, 0,0" Text="[ " Foreground="{Binding DEFAULTCOLOR, Source={StaticResource global}}" />
                    <TextBlock Text="{Binding Critical}" Foreground="{Binding ALARMCOLOR, Source={StaticResource global}}"/>
                    <TextBlock Text=" | " Foreground="{Binding DEFAULTCOLOR, Source={StaticResource global}}"/>
                    <TextBlock Text="{Binding OK}" Foreground="{Binding OKCOLOR, Source={StaticResource global}}"/>
                    <TextBlock Text=" ]" Foreground="{Binding DEFAULTCOLOR, Source={StaticResource global}}"/>
                </StackPanel>
            </StackPanel>
        </common:HierarchicalDataTemplate>

    </UserControl.Resources>

    <Grid>
        <!-- Where the hierarchical template is used --> 
    </Grid>

</UserControl>

Resources中的部分和绑定一样抛出错误:

Unable to cast object of type 'ApplicationProxy' to type 'Microsoft.Expression.DesignModel.DocumentModel.DocumentNode'.

我的代码有什么问题,我怎样才能让它工作?

【问题讨论】:

    标签: xaml binding silverlight-5.0


    【解决方案1】:

    我找到了我的问题所在,因此我找不到任何类似的情况。

    我有public class Global : App - 不要问我为什么,我确信很久以前就有正当理由,但这意味着它正在进行某种时髦的循环引用。

    问题解决了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-06
      • 1970-01-01
      • 2014-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多