検索結果の再利用可能なカスタムコントロールがあります。これは、ListView GridViewを使用して検索結果を表示し、既にアプリの複数の場所で使用されています。コードを使用してカスタムコントロールの子要素を置き換えます。
<views:AbstractDictionaryPickerView x:Class="MyApp.Common.Controls.Dictionaries.Views.AbstractDictionaryPickerView"
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:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:watermark="clr-namespace:MyApp.Common.Controls.Watermark"
xmlns:behaviors="clr-namespace:MyApp.Common.Behaviors"
xmlns:listViewLayout="clr-namespace:Itenso.Windows.Controls.ListViewLayout;assembly=Itenso.Windows.Controls.ListViewLayout"
xmlns:views="clr-namespace:MyApp.Common.Controls.Dictionaries.Views"
xmlns:viewModels="clr-namespace:MyApp.Common.Controls.Dictionaries.ViewModels"
xmlns:design="clr-namespace:MyApp.Common.Controls.Dictionaries.ViewModels.Design"
d:DataContext="{design:DesignMultiDictionaryPickerViewModel}"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Viewbox Stretch="Fill">
<Canvas Width="800" Height="800">
<Rectangle Fill="#ffffffff" Width="800" Height="800" />
<Rectangle Width="5" Height="800" >
<Rectangle.Fill>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#FFCAEBF4"/>
<GradientStop Color="#FFCEF5FF" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Canvas>
</Viewbox>
<Grid Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<TextBox
Grid.Row="0" Height="Auto"
Margin="5,0,5,0"
Style="{StaticResource TextBoxStyle}"
Text="{Binding SearchQuery, UpdateSourceTrigger=PropertyChanged}">
<i:Interaction.Behaviors>
<watermark:TextBoxWatermarkBehavior Label="{Binding WatermarkText, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}"
LabelStyle="{StaticResource WatermarkStyle}"/>
<behaviors:SelectAllWhenTextBoxFocusedBehavior/>
<behaviors:TextBoxArrowUpDownNavigationBehavior/>
<behaviors:SetLogicalFocusBehavior/>
</i:Interaction.Behaviors>
</TextBox>
<Grid Grid.Row="1">
<ListView listViewLayout:ListViewLayoutManager.Enabled="True" x:Name="SearchResultsList"
ItemsSource="{Binding FilteredElements}"
ScrollViewer.VerticalScrollBarVisibility="Auto" Margin="5,2,5,3"
SelectionMode="Single"
>
<ListView.Resources>
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource TextBlockStyle}"/>
</ListView.Resources>
<i:Interaction.Behaviors>
<behaviors:ArrowNavigationBehavior/>
<behaviors:AutoSizeListViewColumns/>
</i:Interaction.Behaviors>
<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewMouseDoubleClick">
<i:InvokeCommandAction Command="{Binding ChooseItemCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListView}}, Path=SelectedItem}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<ListView.InputBindings>
<KeyBinding Key="Enter"
Command="{Binding ChooseItemCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListView}}, Path=SelectedItem}" />
<MouseBinding MouseAction="LeftDoubleClick"
Command="{Binding ChooseItemCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListView}}, Path=SelectedItem}" />
</ListView.InputBindings>
<ListView.View>
<!-- GRIDVIEW TO REPLACE -->
<GridView ColumnHeaderContainerStyle="{StaticResource {x:Type GridViewColumnHeader}}" x:Name="ElementsGridView">
<GridViewColumn Header="">
<GridViewColumn.CellTemplate>
<DataTemplate DataType="viewModels:ChoosableViewModel">
<CheckBox IsChecked="{Binding IsChosen}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
</Grid>
</Grid>
</views:AbstractDictionaryPickerView>
のかかるコードは以下のようになります。
<UserControl x:Class="MyApp.Modules.Management.OnlineRegistrationSettings.Tabs.AvailableDoctors.OnlineRegistrationDoctorsSettingsView"
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:views="clr-namespace:MyApp.Common.Controls.Dictionaries.Views;assembly=MyApp.Common"
xmlns:onlineRegistrationSettings="clr-namespace:MyApp.Modules.Management.OnlineRegistrationSettings"
d:DataContext="{d:DesignInstance onlineRegistrationSettings:OnlineRegistrationSettingsViewModel}"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Style="{StaticResource LabelStyle}" Content="Wybór lekarzy, którzy mają być dostępni w rejestracji online."/>
<!-- HERE -->
<views:AbstractDictionaryPickerView DataContext="{Binding MultiDictionaryPickerViewModel}" Grid.Row="1"
Configuration="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}, Path=DataContext.Configuration}"/>
</Grid>
</UserControl>
は、今私は(コンボボックスを使用して新しい列を追加)GridView
列を変更しますします。
views:AbstractDictionaryPickerView
のGridView
要素を、消費コードのXAMLにオーバーライドすることはできますか?最初のスニペットにある<!-- GRIDVIEW TO REPLACE -->
タグの下にあるものを意味します。