Ich möchte ein Format (Ausrichtung Text, Format für die Währung 0000.00) auf die Spalten in der GridViewColumn anwenden.WPF-Textformatierung in GridViewColumn
<GridViewColumn TextBlock.TextAlignment="Center" Width="80" DisplayMemberBinding="{Binding XPath=Name}"/>
Die Idee ist folgende: In den Spalten (Gridviewcolumn) den Text, der unser ein Format für ihn gelten konnte (Aligner auf der linken Seite, rechts, Mitte, rechtfertigen, etc.).
Im folgenden Code können sie die verschiedenen Versuche sehen, ohne jedes Ergebnis
zu erhaltenDer Code ist wie folgt:
<Window x:Class="ListViewTest.Test0.ListViewTest"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Empty ListView Grid" Height="216" Width="435" FlowDirection="LeftToRight" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.IsSharedSizeScope="False">
<Window.Resources>
<XmlDataProvider x:Key="CustomersDS" Source="C:\data.xml"/>
<Style x:Key="myHeaderStyle" TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Visibility" Value="Collapsed" />
</Style>
</Window.Resources>
<ListView Margin="0,0,0,50" ItemTemplate="{DynamicResource CustomerTemplate}" ItemsSource="{Binding Source={StaticResource CustomersDS}, XPath=/Customers/Customer}">
<ListView.View>
<!--ColumnHeaderContainerStyle="{StaticResource myHeaderStyle}"-->
<GridView >
<GridViewColumn Width="80" TextBlock.TextAlignment="Center">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock HorizontalAlignment="Center" Text="{Binding XPath=Code}"></TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn TextBlock.TextAlignment="Center" Width="80" DisplayMemberBinding="{Binding XPath=Name}"/>
<GridViewColumn Width="120" TextBlock.TextAlignment="center" DisplayMemberBinding="{Binding XPath=Country}"/>
<GridViewColumn Width="120" TextBlock.TextAlignment="center" DisplayMemberBinding="{Binding XPath=money}"/>
</GridView>
</ListView.View>
</ListView>
</Window>
XML
<Customers>
<Customer>
<Code>1234</Code>
<Name>EPI</Name>
<Country>Sesame Street</Country>
<money> 98.00</money>
</Customer>
<Customer>
<Code>3234</Code>
<Name>Paul</Name>
<Country>United Kingdom</Country>
<money> 8.70</money>
</Customer>
<Customer>
<Code>3344</Code>
<Name>Juan</Name>
<Country>Spain</Country>
<money> 785.5</money>
</Customer>
<Customer>
<Code>4321</Code>
<Name>Dodo</Name>
<Country>Venezuela</Country>
<money> 150.02</money>
</Customer>
</Customers>
Es tut mir leid, ich kann es nicht verstehen. Irgendjemand anderes? – Ray
Ich erkläre es besser? Vielen Dank für Ihre Hilfe. – Ozplc
Warum ist diese Frage ein Community-Wiki? –