如何在wpf

时间:2016-03-02 13:15:11

标签: wpf xaml mvvm view triggers

我的代码就是这样。 MyView是用户控件

<DataTemplate DataType="{x:Type vm:MyViewModel}">
    <vw:MyView d:DesignWidth="150" d:DesignHeight="100" />
</DataTemplate>

这是我的tabcontrol - &gt; tabitem datatemplate。我正在创建一个新选项卡,正在创建选项卡,但在我关注选项卡之前,MyView未在选项卡中加载。

当应用程序在场景中创建MyViewModel时,MyView不会填充,直到我关注MyView。如何在填充MyViewModel后立即填充MyView?

更新

首先这是一个自定义TabControl继承Wpf TabControl ...

      <dragablz:TabablzControl 
            Margin="0 -1 -1 0" 
            SelectionChanged="TabControl_SelectionChanged"
            HeaderPrefixContent="{StaticResource WindowIcon}"
            AdjacentHeaderItemOffset="0"
            x:Name="TabControl">

        <DataTemplate DataType="{x:Type viewModel:BrowserTabViewModel}">
            <view:BrowserTabView />
        </DataTemplate>
        <dragablz:TabablzControl.ContentTemplate>
            <DataTemplate DataType="{x:Type viewModel:BrowserTabViewModel}">
                <view:BrowserTabView />
            </DataTemplate>
        </dragablz:TabablzControl.ContentTemplate>
    </dragablz:TabablzControl>
        <Style TargetType="{x:Type dragablz:TabablzControl}" BasedOn="{StaticResource {x:Type dragablz:TabablzControl}}">
            <Setter Property="ItemContainerStyle" Value="{StaticResource TrapezoidDragableTabItemStyle}" />
            <Setter Property="NewItemFactory" Value="{x:Static common2:MainWindow.NewItemFactory}" />
            <Setter Property="ShowDefaultAddButton" Value="True" />
            <Setter Property="ShowDefaultCloseButton" Value="True" />

            <Setter Property="CustomHeaderItemTemplate">
                <Setter.Value>
                    <ItemContainerTemplate DataType="{x:Type viewModel:BrowserTabViewModel}">
                        <DockPanel Width="120px" Height="22">
                            <Image gif:ImageBehavior.AnimatedSource="{Binding Favicon}"
                                   HorizontalAlignment="Left"
                                   Margin="0 0 3 0"
                                   gif:ImageBehavior.AutoStart="True"
                                   RenderOptions.BitmapScalingMode="NearestNeighbor"
                                   RenderOptions.EdgeMode="Aliased"
                                   VerticalAlignment="Center"
                                   Opacity="100"
                                   Width="16" Height="16"></Image>
                            <TextBlock HorizontalAlignment="Left" 
                                       Background="Transparent" Margin="0 0 5 0" 
                                       FontSize="13" VerticalAlignment="Center" 
                                       Width="100px" Text="{Binding Title}"/>
                        </DockPanel>

                    </ItemContainerTemplate>
                </Setter.Value>
            </Setter>
        </Style>

0 个答案:

没有答案