![](/img/trans.png)
[英]C# WPF MVVM XAML: Using ContentPresenter Style to display ViewModel
[英]C# WPF specify folders in XAML style
我有一個具有以下結構的項目:
Proj
├──Views
├ ├──Dashboard.xaml
├ ├──Dashboard.cs
├
├──Styles
├──DashboardStyle.xaml
在我的DashboardStyle.xaml
,我有以下代碼:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Proj.Styles">
<Style x:Key="MyWindowStyle" TargetType="local:Proj/Views/Dashboard">
....
....
</Style>
</ResourceDictionary>
但是它給出了錯誤:
名稱“ Proj / Views / Dashboard”在命名空間“ clr-namespace:Proj.Styles”中不存在
我該如何解決這個問題?
類型是使用namepace和類型名而不是物理文件路徑來引用的。
因此,要引用Proj.Views.Dashboard
類型,請將相應的名稱空間添加為XML名稱空間聲明,並在TargetType屬性中使用它,例如
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Proj.Styles"
xmlns:views="clr-namespace:Proj.Views" >
<Style x:Key="MyWindowStyle" TargetType="views:Dashboard">
....
....
</Style>
</ResourceDictionary>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.