如何使用DesignInstance与Caliburn.Micro [英] how to use DesignInstance with Caliburn.Micro

查看:296
本文介绍了如何使用DesignInstance与Caliburn.Micro的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Caliburn.Micro



我有这个WPF认为,在设计时采用的样本数据成功地在诸如姓名等基本属性,但不能不会找到性能和复杂类型的集合

 <的观点;用户控件X:类=NonRepositoryItems.Reviewer.ReviewerView
的xmlns =htt​​p://schemas.microsoft.com/winfx/2006/xaml/presentation
的xmlns:X =htt​​p://schemas.microsoft.com/winfx/2006/xaml
的xmlns:MC =htt​​p://schemas.openxmlformats.org/markup-compatibility/2006
的xmlns:D =htt​​p://schemas.microsoft.com/expression/blend/2008
的xmlns:控制=CLR的命名空间:MyFramework.Controls.BusyIndi​​cator.Implementation;装配= App.Framework
的xmlns:CAL =htt​​p://www.caliburnproject.org
的xmlns: FormPanel中=CLR的命名空间:MyFramework.Controls.FormPanel;装配= App.Framework
的xmlns:的sampleData =CLR的命名空间:NonRepositoryItems.SampleData
MC:可忽略=D
D:的DataContext ={D:DesignInstance的sampleData:SampleReviewerViewModel,IsDesignTimeCreatable = TRUE}
>
<网格和GT;
< BORDER>
<&DockPanel中GT;
< D​​ockPanel.Resources>
<风格的TargetType =标签>
< setter属性=粗细VALUE =大胆/>
< setter属性=字号VALUE =12/>
< /样式和GT;
<风格的TargetType =TextBlock的>
< setter属性=VerticalAlignmentVALUE =中心/>
< /样式和GT;
< /DockPanel.Resources>
< FormPanel中:FormPanel中列=2保证金=5DockPanel.Dock =评出的>
<标签内容=职位名称/>
< TextBlock的文本={结合JOBTITLE}/>

<标签内容=敬/>
< TextBlock的文本={结合敬}/>

<标签内容=名/>
< TextBlock的文本={结合姓}/>

<标签内容=姓/>
< TextBlock的文本={结合姓氏}/>

<标签内容=性别/>
< TextBlock的文本={结合性别}/>

< / FormPanel中:FormPanel中>

< FormPanel中:FormPanel中列=1保证金=5DockPanel.Dock =评出的>
<标签内容=邮寄地址/>
< ContentControl中CAL:View.Model ={结合的PostalAddress}/>
<标签内容=快递地址/>
< ContentControl中CAL:View.Model ={结合CourierAddress}/>
< / FormPanel中:FormPanel中>
< ListView控件的ItemsSource ={结合RepositoryItems}>< /&的ListView GT;
< / DockPanel中>

< /边框>

<控制:BusyIndi​​cator控件IsBusy ={结合IsBusy}BusyContent =忙......Grid.ColumnSpan =2>< /控制:BusyIndi​​cator控件>
< ContentControl中X:NAME =对话框
VerticalContentAlignment =拉伸
Horizo​​ntalContentAlignment =拉伸/>
< /网格和GT;
< /用户控件>

下面是sampleData在



 公共类SampleReviewerViewModel:ReviewerViewModel 
{
公共SampleReviewerViewModel()
{
=敬语先生;
名字=约翰;
姓氏=史密斯;
ReviewerId =125634;
性别=男;
JOBTITLE =REC椅子;
ReviewerTaskCount =10;
ReviewerRequestedTaskCount =20;
ReviewerDispatchedTaskCount =33;
ReviewerRequestedReturnedCount =50;
的PostalAddress =新AddressViewModel();
CourierAddress =新AddressViewModel();
IsBusy = FALSE;
RepositoryItems =新的ObservableCollection< RepositoryItemViewModel>
{
新RepositoryItemViewModel(){标题=红色},
新RepositoryItemViewModel(){标题=橙色},
新RepositoryItemViewModel(){标题=黄},
新RepositoryItemViewModel(){标题=绿色},
新RepositoryItemViewModel(){标题=蓝},
新RepositoryItemViewModel(){标题=靛蓝} ,
新RepositoryItemViewModel(){标题=紫罗兰}
};
}

}

下面是我的地址查看

 <用户控件X:类=NonRepositoryItems.Reviewer.AddressView
的xmlns =htt​​p://schemas.microsoft .COM / WinFX的/ 2006 / XAML /演示
的xmlns:X =http://schemas.microsoft.com/winfx/2006/xaml
的xmlns:MC =HTTP://模式.openxmlformats.org /标记兼容性/ 2006
的xmlns:D =http://schemas.microsoft.com/expression/blend/2008
的xmlns:的sampleData =CLR的命名空间:NonRepositoryItems .SampleDataMC:可忽略=D
D:的DataContext ={D:DesignInstance的sampleData:SampleAddressViewModel,IsDesignTimeCreatable = TRUE}
>

< BORDER>
<电网保证金=4>
<&StackPanel的GT;
< TextBlock的文本={结合AddressLine1}能见度={结合IsAddressLine1Visible,转换器= {StaticResource的booleanToVisibility}}/>
< TextBlock的文本={结合AddressLine2}能见度={结合IsAddressLine2Visible,转换器= {StaticResource的booleanToVisibility}}/>
< TextBlock的文本={结合AddressLine3}能见度={结合IsAddressLine3Visible,转换器= {StaticResource的booleanToVisibility}}/>
< TextBlock的文本={结合城市}能见度={结合IsCityVisible,转换器= {StaticResource的booleanToVisibility}}/>
< TextBlock的文本={结合邮编}能见度={结合IsPostCodeVisible,转换器= {StaticResource的booleanToVisibility}}/>
< TextBlock的文本={结合国家}能见度={结合IsCountryVisible,转换器= {StaticResource的booleanToVisibility}}/>
< / StackPanel的>
< /网格和GT;
< /边框>
< /用户控件>

和它的样本数据

 公共类SampleAddressViewModel:AddressViewModel 
{

公共SampleAddressViewModel()
{
TYPE =邮件地址;
AddressLine1 =350第五大道;
AddressLine2 =;
AddressLine3 =;
市=纽约,纽约;
邮编=10118;
国=美利坚合众国;
}
}


解决方案

唐'T需要 CAL:Bind.AtDesignTime =真在用户控件

 <用户控件X:类=NonRepositoryItems.Reviewer.AddressView
的xmlns =htt​​p://schemas.microsoft.com/winfx/2006/xaml/presentation
的xmlns: X =htt​​p://schemas.microsoft.com/winfx/2006/xaml
的xmlns:MC =htt​​p://schemas.openxmlformats.org/markup-compatibility/2006
的xmlns: D =htt​​p://schemas.microsoft.com/expression/blend/2008
的xmlns:的sampleData =CLR的命名空间:NonRepositoryItems.SampleDataMC:可忽略=D
D:DataContext的= {D:DesignInstance的sampleData:SampleAddressViewModel,IsDesignTimeCreatable = TRUE}
CAL:Bind.AtDesignTime =真>


I am using Caliburn.Micro

I have this WPF View that in design time uses sample data successfully on basic properties like firstname etc but can't won't find the view for properties and collections of complex types

<UserControl x:Class="NonRepositoryItems.Reviewer.ReviewerView"
         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:Controls="clr-namespace:MyFramework.Controls.BusyIndicator.Implementation;assembly=App.Framework"
         xmlns:cal="http://www.caliburnproject.org"
         xmlns:FormPanel="clr-namespace:MyFramework.Controls.FormPanel;assembly=App.Framework"
         xmlns:SampleData="clr-namespace:NonRepositoryItems.SampleData"
         mc:Ignorable="d" 
         d:DataContext="{d:DesignInstance SampleData:SampleReviewerViewModel, IsDesignTimeCreatable=True}"
         >
<Grid>
    <Border>
        <DockPanel>
            <DockPanel.Resources>
                <Style TargetType="Label"  >
                    <Setter Property="FontWeight" Value="Bold" />
                    <Setter Property="FontSize" Value="12" />
                </Style>
                <Style TargetType="TextBlock"  >
                    <Setter Property="VerticalAlignment" Value="Center" />
                </Style>
            </DockPanel.Resources>
            <FormPanel:FormPanel Columns="2" Margin="5" DockPanel.Dock="Top">
                <Label Content="Job Title"/>
                <TextBlock Text="{Binding JobTitle}"  />

                <Label Content="Honorific"/>
                <TextBlock Text="{Binding Honorific}" />

                <Label Content="First Name"/>
                <TextBlock Text="{Binding FirstName}" />

                <Label Content="Last Name"/>
                <TextBlock Text="{Binding LastName}" />

                <Label Content="Gender"/>
                <TextBlock Text="{Binding Gender}"    />

            </FormPanel:FormPanel>

            <FormPanel:FormPanel Columns="1" Margin="5" DockPanel.Dock="Top">
                <Label Content="Postal Address"/>                    
                <ContentControl cal:View.Model="{Binding PostalAddress}" />        
                <Label Content="Courier Address"/>
                <ContentControl cal:View.Model="{Binding CourierAddress}"  />
            </FormPanel:FormPanel>
            <ListView ItemsSource="{Binding RepositoryItems}"></ListView>
        </DockPanel>

    </Border>

    <Controls:BusyIndicator IsBusy="{Binding IsBusy}" BusyContent="Busy..." Grid.ColumnSpan="2"></Controls:BusyIndicator>
    <ContentControl x:Name="Dialogs" 
                    VerticalContentAlignment="Stretch"
                    HorizontalContentAlignment="Stretch"/>
</Grid>
</UserControl>

Here is the SampleData

public class SampleReviewerViewModel : ReviewerViewModel
{
    public SampleReviewerViewModel()
    {
        Honorific = "Mr";
        FirstName = "John";
        LastName = "Smith";
        ReviewerId = "125634";
        Gender = "Male";
        JobTitle = "REC Chair";
        ReviewerTaskCount = "10";
        ReviewerRequestedTaskCount = "20";
        ReviewerDispatchedTaskCount = "33";
        ReviewerRequestedReturnedCount = "50";
        PostalAddress = new AddressViewModel();
        CourierAddress = new AddressViewModel();
        IsBusy = false;
        RepositoryItems = new ObservableCollection<RepositoryItemViewModel>
                        {
                            new RepositoryItemViewModel() {Title = "Red"      },
                            new RepositoryItemViewModel() {Title = "Orange"   },
                            new RepositoryItemViewModel() {Title = "Yellow"   },
                            new RepositoryItemViewModel() {Title = "Green"    },
                            new RepositoryItemViewModel() {Title = "Blue"     },
                            new RepositoryItemViewModel() {Title = "Indigo"   },
                            new RepositoryItemViewModel() {Title = "Violet"   }
                        };
    }

}

Here is my address view

<UserControl x:Class="NonRepositoryItems.Reviewer.AddressView"
         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:SampleData="clr-namespace:NonRepositoryItems.SampleData" mc:Ignorable="d" 
          d:DataContext="{d:DesignInstance SampleData:SampleAddressViewModel, IsDesignTimeCreatable=True}"
         >

<Border>
<Grid Margin="4">
    <StackPanel>
            <TextBlock Text="{Binding AddressLine1}"  Visibility="{Binding IsAddressLine1Visible, Converter={StaticResource booleanToVisibility}}"/>
            <TextBlock Text="{Binding AddressLine2}"  Visibility="{Binding IsAddressLine2Visible, Converter={StaticResource booleanToVisibility}}" />
            <TextBlock Text="{Binding AddressLine3}"  Visibility="{Binding IsAddressLine3Visible, Converter={StaticResource booleanToVisibility}}" />
            <TextBlock Text="{Binding City}"          Visibility="{Binding IsCityVisible, Converter={StaticResource booleanToVisibility}}"/>
            <TextBlock Text="{Binding PostCode}"      Visibility="{Binding IsPostCodeVisible, Converter={StaticResource booleanToVisibility}}"/>
            <TextBlock Text="{Binding Country}"       Visibility="{Binding IsCountryVisible, Converter={StaticResource booleanToVisibility}}"/>
    </StackPanel>
</Grid>
</Border>
</UserControl>

and it's sample data

public class SampleAddressViewModel : AddressViewModel
{

    public SampleAddressViewModel()
    {
        Type = "Mail Address";
        AddressLine1 = "350 Fifth Avenue";
        AddressLine2 = "";
        AddressLine3 = "";
        City = "New York, NY ";
        PostCode = "10118";
        Country = "United States of America";
    }
}

解决方案

Don't you need cal:Bind.AtDesignTime="True" on your user control.

<UserControl x:Class="NonRepositoryItems.Reviewer.AddressView"
         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:SampleData="clr-namespace:NonRepositoryItems.SampleData" mc:Ignorable="d" 
          d:DataContext="{d:DesignInstance SampleData:SampleAddressViewModel, IsDesignTimeCreatable=True}"
         cal:Bind.AtDesignTime="True">

这篇关于如何使用DesignInstance与Caliburn.Micro的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆