问题
For instance I have the next code for my BaseView:
using System.Windows;
using DevExpress.Xpf.Core;
namespace Infrastructure.BaseView
{
public class BaseView : LoadingDecorator
{
public BaseView()
{
Style = FindResource("BaseViewStyle") as Style;
}
}
}
Style:
<Style TargetType="{x:Type baseView:BaseView}" x:Key="BaseViewStyle" >
<Setter Property="OwnerLock" Value="InputOnly"/>
<Style.Triggers>
<DataTrigger Binding="{Binding State}" d:DataContext="{d:DesignInstance Type=baseViewModel:BaseViewModel}">
<DataTrigger.Value>
<enums:ViewState>Busy</enums:ViewState>
</DataTrigger.Value>
<Setter Property="IsSplashScreenShown" Value="True" />
</DataTrigger>
<DataTrigger Binding="{Binding State}" d:DataContext="{d:DesignInstance Type=baseViewModel:BaseViewModel}">
<DataTrigger.Value>
<enums:ViewState>Default</enums:ViewState>
</DataTrigger.Value>
<Setter Property="IsSplashScreenShown" Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
Then I create specific view like this(name space definition is not so simple because view has really complex UI):
<baseView:BaseView x:Class="General.Views.ProjectListView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:baseView="clr-namespace:Infrastructure.BaseView;assembly=Infrastructure"
xmlns:viewModels="clr-namespace:General.ViewModels"
xmlns:dxprg="http://schemas.devexpress.com/winfx/2008/xaml/propertygrid"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="1000"
d:DataContext="{d:DesignInstance Type=viewModels:ProjectListViewModel, IsDesignTimeCreatable=True}"
x:Name="View"
...
</baseView:BaseView>
In run time everything works perfect, but I have a compile time error:
Error 4 Cannot create an instance of "BaseView".
And Designer in my VS does not work. And in it's StackTrace I can watch next information
at System.Windows.Style.CheckTargetType(Object element)
at System.Windows.StyleHelper.UpdateStyleCache(FrameworkElement fe, FrameworkContentElement fce, Style oldStyle, Style newStyle, Style& styleCache)
at System.Windows.FrameworkElement.OnStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
...
I realized that the problem in TargetType="{x:Type baseView:BaseView}"
in my style, but without this code my style shows me errors and not works and I understand it.
How can I remove this compile time error?
It is ok to use LoadingDecorator
for BaseView? I think that if I have some views in display and some of its can be busy, some - not. So, I thought to do it will be good.
I use PRISM in my app and I thought to take out LoadingDecorator
in Shell.xaml
beyond every regions but in this case I don't understand how can I bind IsSplashScreenShown
to specific ViewModel of specific View.
来源:https://stackoverflow.com/questions/32695109/compile-time-error-when-styling-baseview-like-loadingdecorator