如何更新TabControl资源?

时间:2016-02-23 18:05:00

标签: c# wpf mvvm

我的视图中有一个制表符控件,绑定到一个可观察的集合。但是当我打电话给RaisePropertyChanged时,没有任何更新。启用了选项卡,但选项卡内的视图没有。如何刷新数据模板中的视图?

<TabControl IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding DeviceListViewModel.SelectedDevice.TabViewModelsCollection, UpdateSourceTrigger=PropertyChanged}" SelectedItem="{Binding DeviceListViewModel.SelectedDevice.SelectedTabItemVm}"   >
                <TabControl.Resources>
                    <DataTemplate DataType="{x:Type vms:HomeViewModel}">
                        <local:HomeTab/>
                    </DataTemplate>
                    <DataTemplate DataType="{x:Type vms:ConfigurationViewModel}">
                        <Grid>
                            <local:ConfigurationFileView  Visibility="{Binding Configuration, TargetNullValue=Collapsed, FallbackValue=Visible}"/>
                            <local:ErrorTab  Visibility="{Binding Path= Configuration, TargetNullValue=Visible, FallbackValue=Hidden}"/>
                        </Grid>
                    </DataTemplate>
                    <DataTemplate DataType="{x:Type vms:ExpansionModulesViewModelFactory}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="35"/>
                            </Grid.RowDefinitions>
                            <StackPanel Grid.Row="0">
                                <DockPanel >
                                    <local:ExpansionModulesList Title="Discovered/Enumerated" 
                                                        DataContext="{Binding DiscoveredModules}" 
                                                       />
                                    <GridSplitter Width="5"/>
                                    <local:ExpansionModulesList Title="User Action Required" 
                                                        DataContext="{Binding FaultyModules}" 
                                                        />
                                </DockPanel>
                            </StackPanel>
                            <DockPanel Grid.Row="1">
                                <StackPanel Orientation="Horizontal" FlowDirection="RightToLeft" Margin="5" IsEnabled="{Binding IsCommandEnabled}">
                                    <Button Content="Cancel" HorizontalAlignment="Right"             
                                            Command="{Binding CancelExpansionCommand }"
                                            ToolTip="Revert all local modifications by refreshing data from the controller." />                                                                                                                                  
                                    <Separator Width="10"/>

                                    <Button Content="Apply"  HorizontalAlignment="Center"                         
                                            Command="{Binding ApplyExpansionCommand }"
                                            ToolTip="Apply all changes to the controller." />
                                    <Separator/>
                                </StackPanel>
                            </DockPanel>
                        </Grid>
                    </DataTemplate>
                    <DataTemplate DataType="{x:Type vms:LogViewModel}">
                        <local:LogView  />
                    </DataTemplate>
                    <DataTemplate DataType="{x:Type vms:SignalStrengthViewModel}">
                        <local:SignalStrengthView  />
                    </DataTemplate>
                </TabControl.Resources>

                <TabControl.ItemContainerStyle>

                    <Style TargetType="{x:Type TabItem}">
                        <Setter Property="Header" Value="{Binding Name}" />
                        <Setter Property="IsEnabled" Value="{Binding IsEnabled}" />
                        <Setter Property="Header" Value="{Binding Name}" />
                    </Style>
                </TabControl.ItemContainerStyle>


                <!--End Device List-->
            </TabControl>

1 个答案:

答案 0 :(得分:0)

实际上我无法理解为什么不更新你的观点,我想你必须告诉我你的背后代码。 你可以尝试任何方式:

            tabControl.UpdateLayout();

            tabControl.UpdateDefaultStyle();