2011-02-23 68 views
2

我在RadTileView中有一個ContentControl。如果我將一些硬編碼文本放入內容屬性中,它可以正常工作。 (代碼如下)資源ContentControl的內容

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

這有效......如果我把內容放到UserControl.Resources部分,我的應用程序就會凍結並不顯示任何內容。

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

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

最終我想有一個RadTabControl的上下文..但現在Id定居只是有文本塊渲染。

回答

1

得到一個字符串到您的ContentControl中,你會加

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

您usings。然後添加此

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

這將使

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

希望這有助於。

+0

好的..我會試試這個..最後我需要添加這個而不是文本塊.. - 我明白你要去哪裏我會試試這個路徑... – gevjen 2011-02-23 21:21:36

+0

Rus ..上面的代碼工作完美..現在即將嘗試使用該telerik radtabcontrol做到這一點... – gevjen 2011-02-23 21:24:51

+0

如果您在您的項目中使用MVVM方法,我會考慮用您自己的viewModel將您的RadTabControl包裝在一個UserControl中,將視圖的組成保留在XAML標記之外。 – Rus 2011-02-23 21:47:42

相關問題