开发者

Content of ContentControl in Resource

开发者 https://www.devze.com 2023-02-12 19:41 出处:网络
I have a ContentControl 开发者_运维技巧in a RadTileView. If I put in some hard coded text into the content property it works fine. (code below)

I have a ContentControl 开发者_运维技巧in a RadTileView. If I put in some hard coded text into the content property it works fine. (code below)

 <ContentControl Grid.Row="2" Grid.Column="0" Content="Hello World"></ContentControl>

That works...if I put the content into the UserControl.Resources section my application freezes up and displays nothing.

<ContentControl Grid.Row="2" Grid.Column="0" Content="{StaticResource TabControlContent}"></ContentControl>

<UserControl.Resources>
        <TextBlock x:Key="TabControlContent" Text="hello world"></TextBlock>
</UserControl.Resources>

Ultimately I would like to have the context be a RadTabControl..but for now Id settle on just having that textblock render.


To get a string into your ContentControl you would, add

xmlns:sys="clr-namespace:System;assembly=mscorlib"

to your usings. Then add this

<UserControl.Resources>
        <sys:String x:Key="SingleString">Hello World</sys:String>
</UserControl.Resources>

Which would allow

<ContentControl Content="{Binding Source={StaticResource SingleString}}"/>

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号