Announcement

Collapse
No announcement yet.

XAML Binding in WPF funktioniert nicht

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • XAML Binding in WPF funktioniert nicht

    Hallo Community,

    ich stehe vor einem mysteriösen Problem, das ich gerne verstehen würde. Es geht mir also nicht um work-arounds, sondern darum zu verstehen, warum es nicht läuft, und natürlich wäre ich für eine Lösung (möglichst ohne andere Konstrukte zu verwenden) dankbar . Ich möchte das xml:lang Attribut nach der aktuellen CultureInfo setzen, was in dieser paremetrisierten Weise leider nicht funktioniert (Betreffende Zeilen in Bold):

    Code:
    <Window x:Class="License_Client.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:glob="clr-namespace:System.Globalization;assembly=mscorlib"...
    		<DataGridTemplateColumn Header="Expiration Date" Width="120" SortMemberPath="StartDate">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Grid Margin="1">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="80"/>
                                        <ColumnDefinition Width="*"/>
                                    </Grid.ColumnDefinitions>
                                    <Border Background="Azure" Padding="2">
                                        <TextBlock xml:lang="{Binding Source={x:Static glob:CultureInfo.CurrentCulture}, Path=Name}"                                              
                                                                              Foreground="Black" Text="{Binding ExpirationDate,StringFormat=dd.MMMM}"/>
                                    </Border>
                                    <Border Grid.Column="4" Background="LightGray" Padding="2">
                                        <TextBlock Text="{Binding ExpirationDate,StringFormat=yyyy}"/>
                                    </Border>
                                </Grid>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                        <DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <DatePicker SelectedDate="{Binding ExpirationDate}" DisplayDateStart="{Binding ExpirationDate}"
                                            DisplayDateEnd="{Binding MaxExpirationDate}" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellEditingTemplate>
                    </DataGridTemplateColumn>
    ...
    Wenn ich aber die betreffende Zeile z.B. mit

    Code:
    <TextBlock xml:lang="de-DE"
    setze sorgt der entsprechende Converter dafür, dass dieser String in das entsprechende XMLLanguage Objekt verwandelt wird. Die statische CultureInfo.CurrentCulture property, die als Source eingebunden wird liefert das CultureInfo Objekt, das für die aktuelle Culture steht. Das Name-Property was mit "Path" angesprochen wird liefert einen String, z.B. "de-DE", d.h. eigentlich genau dasselbe, wie wenn ich direkt "de-DE" eingegeben hätte. Warum liefert der Compiler mir dann eine XamlParseException, obwohl die Ergebnisse auf der rechten Seite des Gleichheitszeichens gleichermassen "de-DE" sind? Wenn ich diesen Ausdruck an eine TextBox binde, zeigt sie mir "de-DE" auch an, also ist da kein Syntax-Fehler vorhanden. Ich habe die obersten Zeilen der Exception-Details mal unten mitaufgeführt, vielleicht wird jemand daraus ja klug..

    Danke im Voraus!

    System.Windows.Markup.XamlParseException was unhandled
    Message=Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtens ion' threw an exception.
    Source=PresentationFramework
    LineNumber=0
    LinePosition=0
    StackTrace:
    at System.Windows.Markup.XamlReader.RewrapException(E xception e, Uri baseUri)
    at System.Windows.FrameworkTemplate.LoadTemplateXaml( XamlReader templateReader, XamlObjectWriter currentWriter)
    at System.Windows.FrameworkTemplate.LoadTemplateXaml( XamlObjectWriter objectWriter)
    at System.Windows.FrameworkTemplate.LoadOptimizedTemp lateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField)
    at System.Windows.FrameworkTemplate.LoadContent(Depen dencyObject container, List`1 affectedChildren)
    at System.Windows.StyleHelper.ApplyTemplateContent(Un commonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate)
    at System.Windows.FrameworkTemplate.ApplyTemplateCont ent(UncommonField`1 templateDataField, FrameworkElement container)
    at System.Windows.FrameworkElement.ApplyTemplate()
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    at System.Windows.UIElement.Measure(Size availableSize)
    at MS.Internal.Helper.MeasureElementWithSingleChild(U IElement element, Size constraint)
    at System.Windows.Controls.ContentPresenter.MeasureOv erride(Size constraint)
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    at System.Windows.UIElement.Measure(Size availableSize)
    at System.Windows.Controls.Border.MeasureOverride(Siz e constraint)
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    at System.Windows.UIElement.Measure(Size availableSize)
    at System.Windows.Controls.Control.MeasureOverride(Si ze constraint)
    at System.Windows.Controls.DataGridCell.MeasureOverri de(Size constraint)
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    at System.Windows.UIElement.Measure(Size availableSize)
    at System.Windows.Controls.DataGridCellsPanel.Measure Child(UIElement child, Size constraint)
    at System.Windows.Controls.DataGridCellsPanel.Generat eChild(IItemContainerGenerator generator, Size constraint, DataGridColumn column, Int32& childIndex, Size& childSize)
    at System.Windows.Controls.DataGridCellsPanel.Generat eChildren(IItemContainerGenerator generator, Int32 startIndex, Int32 endIndex, Size constraint)
    at System.Windows.Controls.DataGridCellsPanel.Generat eAndMeasureChildrenForRealizedColumns(Size constraint)
    at System.Windows.Controls.DataGridCellsPanel.Measure Override(Size constraint)
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    at System.Windows.UIElement.Measure(Size availableSize)
    at MS.Internal.Helper.MeasureElementWithSingleChild(U IElement element, Size constraint)
    at System.Windows.Controls.ItemsPresenter.MeasureOver ride(Size constraint)
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    at System.Windows.UIElement.Measure(Size availableSize)
    at System.Windows.Controls.Control.MeasureOverride(Si ze constraint)
    at System.Windows.Controls.Primitives.DataGridCellsPr esenter.MeasureOverride(Size availableSize)
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    at System.Windows.UIElement.Measure(Size availableSize)
    at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
    at System.Windows.Controls.Grid.MeasureCellsGroup(Int 32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
    at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    at System.Windows.UIElement.Measure(Size availableSize)
    at System.Windows.Controls.Border.MeasureOverride(Siz e constraint)
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    at System.Windows.UIElement.Measure(Size availableSize)
    at System.Windows.Controls.Control.MeasureOverride(Si ze constraint)
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    at System.Windows.UIElement.Measure(Size availableSize)
    at System.Windows.Controls.VirtualizingStackPanel.Mea sureOverride(Size constraint)
    at System.Windows.Controls.Primitives.DataGridRowsPre senter.MeasureOverride(Size constraint)
    at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
    at System.Windows.UIElement.Measure(Size availableSize)
    at System.Windows.ContextLayoutManager.UpdateLayout()
    at System.Windows.UIElement.UpdateLayout()
    at System.Windows.Interop.HwndSource.SetLayoutSize()
    at System.Windows.Interop.HwndSource.set_RootVisualIn ternal(Visual value)
    at System.Windows.Interop.HwndSource.set_RootVisual(V isual value)
    at System.Windows.Window.SetRootVisual()
    at System.Windows.Window.SetRootVisualAndUpdateSTC()
    at System.Windows.Window.SetupInitialState(Double requestedTop, Double requestedLeft, Double requestedWidth, Double requestedHeight)
    at System.Windows.Window.CreateSourceWindow(Boolean duringShow)
    at System.Windows.Window.CreateSourceWindowDuringShow ()
    at System.Windows.Window.SafeCreateWindowDuringShow()
Working...
X