我正在开发一个程序,它提供了一个易于使用的界面来编辑配置文件。配置文件包含两个部分,这两个部分被分为两个不同的列表。
现在两个列表在视觉上应该是相同的(如上所述),如果可能的话,不会复制代码,因此我没有相同的代码两次,只有绑定不同。我正在使用MVVM-Pattern,那就是TabItem的XAML-Code:
<TabItem Header="Windows">
<Grid Background="#FFE5E5E5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="10"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="10"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="30"/>
<RowDefinition Height="10"/>
</Grid.RowDefinitions>
<Label Grid.Row="1" Grid.Column="1" Content="Kreditoren Software"/>
<Label Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Margin="135,0,0,0" HorizontalAlignment="Right">
<Label.Content>
<Binding Path="CfgVersion"/>
</Label.Content>
<Label.ContentStringFormat>
File-Version: {0}
</Label.ContentStringFormat>
</Label>
<Border Background="{StaticResource BrushC1}" BorderThickness="1" BorderBrush="{StaticResource BrushC6}"
HorizontalAlignment="Stretch" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" >
<Grid HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ContentControl
Grid.Column="0"
Content=""
Foreground="{StaticResource BrushC7}"
Effect="{StaticResource ShadowS11}"
Margin="0"
Style="{StaticResource ico_search}"
Height="{StaticResource IconHeight}"
Width="{StaticResource IconWidth}"
VerticalAlignment="Center"
HorizontalAlignment="Left"
IsTabStop="False"
TabIndex="-1"/>
<TextBox Grid.Column="1" Height="20" Width="Auto" Text="{Binding FilterText, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" BorderThickness="0" Margin="0,4" GotFocus="TextBox_GotFocus"/>
</Grid>
</Border>
<ListView x:Name="Kred_ListView" Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,5" ItemsSource="{Binding Kreditoren, Mode=OneWay}" SelectedItem="{Binding SelectedKreditor, Mode=TwoWay}" MouseLeftButtonDown="MouseClick">
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="behavior:ListViewBehavior.IsBroughtIntoViewWhenSelected" Value="true"/>
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.IsListEditable}" Value="True"/>
<Condition Binding="{Binding RelativeSource={RelativeSource Mode=Self}, Path=IsSelected}" Value="true"/>
</MultiDataTrigger.Conditions>
<Setter Property="behavior:ListViewBehavior.IsBroughtIntoViewWhenSelected" Value="true"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock>
<Hyperlink Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.RemoveKreditorCommand}">
<Image Grid.Column="0" Height="20" Source="/S-Param;component/Resources/delete.png" Margin="5,0"/>
</Hyperlink>
</TextBlock>
<Border Grid.Column="1" BorderThickness="1" BorderBrush="Black">
<TextBox Height="18" Text="{Binding Name, Mode=TwoWay}" HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Margin" Value="0,5"/>
</MultiDataTrigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
</ListView>
<Button Grid.Row="4" Grid.Column="1" Content="Bearbeiten" Visibility="{Binding IsEditButtonVisible}" Margin="100,0,10,0" Command="{Binding EditCommand}"/>
<Button Grid.Row="4" Grid.Column="2" Content="Speichern" Visibility="{Binding IsEditButtonVisible}" Margin="0" Command="{Binding SaveCommand}"/>
<Button Grid.Row="4" Grid.Column="2" Content="Übernehmen" Visibility="{Binding IsSaveListButtonVisible}" Margin="0" Command="{Binding SaveListCommand}"/>
<Button Grid.Row="4" Grid.Column="1" Content="Neu..." Visibility="{Binding IsSaveListButtonVisible}" Margin="100,0,10,0" Command="{Binding AddKreditorCommand}"/>
</Grid>
</TabItem>
如果需要进一步的信息,我会尝试追加它们。
如果存在语法错误或拼写错误,请随时纠正错误。