I am trying to bind the Date attribute of the CalendarDatePicker with a DateTime property in a Windows 10 Universal App:
<CalendarDatePicker
Date="{Binding ClientDetailsViewModel.BirthDate,
Converter={StaticResource DateTimeToDateTimeOffsetConverter} }"
Foreground="{StaticResource TextGreyBrush}" />
I am getting the following exception while the view initializes:
An exception of type 'Windows.UI.Xaml.Markup.XamlParseException'
occurred in KLMMobile.UI.exe but was not handled in user code
WinRT information: Failed to assign to property
'Windows.UI.Xaml.Controls.CalendarDatePicker.Date'. [Line: 93
Position: 41]
I've tested it with the DatePicker and it worked perfectly.
After lots of effort trying to bind the Date, I overcame this problem by using a trigger for DateChanged and binding the PlaceHolderText with the Property that should be displayed at start.
<CalendarDatePicker
PlaceholderText="{Binding UpdateWorkingTimeModel.StartTime, Converter={StaticResource TicksToDateTimeConverter}, ConverterParameter='dd.MM.yyyy', Mode=TwoWay}">
<interactivity:Interaction.Triggers>
<interactivity:EventTrigger EventName="DateChanged">
<interactivity:InvokeCommandAction Command="{Binding DatePickedCommand}"/>
</interactivity:EventTrigger>
</interactivity:Interaction.Triggers>
</CalendarDatePicker>
Related
With the {x:Bind} markup syntax you can bind to events provided the method meets the following requirements:
Match the signature of the event.
OR have no parameters.
OR have the same number of parameters of types that are assignable from the types of the event parameters.
This works perfectly fine outside of a DataTemplate. Once the binding happens inside the DataTemplate the compiler generates the following error:
Xaml Internal Error error WMC9999: Object reference not set to an
instance of an object.
What is the fix for binding to events inside DataTemplates?
Full example code here.
Snippet of the example code below - note the first button (line 2) is fine and the second button (line 6) is also fine. If you comment out line 6 and and comment in line 7, the error occurs.
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Button Tapped="{x:Bind Click}" Content="WORKING"/>
<ListView ItemsSource="{x:Bind Names}">
<ListView.ItemTemplate>
<DataTemplate x:DataType="local:Customer">
<Button Content="{x:Bind Title}"/>
<!--<Button Tapped="{x:Bind Clicky}" Content="{x:Bind Title}"/>-->
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackPanel>
I was able to get it to work with the following code:
<DataTemplate x:DataType="local:Customer">
<StackPanel Orientation="Vertical">
<Button Tapped="{x:Bind Clicky}" Content="{x:Bind Title}" />
</StackPanel>
</DataTemplate>
It seems as though you need to have it inside a container for it work. I have no idea why I am guessing magic.
The parser cannot find Clicky from the datacontext of the button while in the template. Because the object that is being handed to the button in the template (from the Names on the ItemSource of the parent) is not the same as outside the template which has a Clicky. You will need to bind Clicky to the page's datacontext to get it to work.
Otherwise turn off any design time operations by setting Tapped="{x:Bind Clicky, IsDesignTimeCreatable=False}.
I am developing a Universal Windows 10 application that will use maps control. In a view I have something like this:
<maps:MapControl Grid.Column="1" MapServiceToken="...">
<maps:MapPolyline StrokeColor="Navy" StrokeThickness="2"
Path="{Binding LineRoute.DirectionAStreetVertices,
Converter={StaticResource LineRouteEntryEnumerableToGeoPathConverter}}" />
</maps:MapControl>
When I build the application successfully and reach that page, I receive a XamlParseException, with a message like "
Cannot deserialize XBF metadata property list as 'StrokeColor' was not found in type 'Windows.UI.Xaml.Controls.Maps.MapPolyline'. [Line: 0 Position: 0]"
If I remove the StrokeColor and StrokeThickness, there isn't any error, but I won't see any polyline at all, of course.
I have the following code in which I hide a WebView just under the main Grid (LayoutRoot) so I can do a sliding animation later:
<Page...>
<Grid x:Name="LayoutRoot">
...
<Grid x:Name="ContentRoot">
...
</Grid>
<WebView...>
<WebView.RenderTransform>
<CompositeTransform TranslateY="{Binding ElementName=LayoutRoot,
Path=ActualHeight}"/> <!--Does not work-->
</WebView.RenderTransform>
</WebView>
</Grid>
</Page>
When I first type the {Binding ElementName=...} line into the designer, the WebView appears just below the Grid like it should. However, when I rebuild the solution or run the app, the WebView simply obscures the whole LayoutRoot.
This will happen regardless of what I am binding to/whatever the control is; however, binding to the exact same expression will show up properly in the designer and in the phone. To demonstrate what I am saying:
<Button Width="{Binding ElementName=LayoutRoot, Path=ActualHeight}"> <!--Works perfectly, both on designer and phone-->
<Button.RenderTransform>
<CompositeTransform SomeProperty={Binding ElementName=SomeElement, Path=SomePath}"/> <!--This does not work-->
</Button.RenderTransform>
</Button>
Is there any way to bind to LayoutRoot.ActualHeight short of writing C# code for this?
One problem you have is you are trying to bind to ActualHeight which is not a dependency property nor an observable (INotifyPropertyChanged) property, so the binding is only evaluated once when it's first created.
I've got this XAML:
<AppBarButton Icon="Protected" Label="Privacy Policy" >
<AppBarButton.Flyout>
<StackPanel>
<Flyout>
<TextBlock Text="Photrax extracts information from images you load into it. The information it extracts includes location information (where the photos were taken, when that is available) and the date and time the photo was taken. This data is stored in a local/internal/embedded (SQLite) database. This data is not stored in the cloud but only on your local device." TextWrapping="Wrap" FontSize="26" FontFamily="Verdana">
</TextBlock>
<TextBlock Text="To reiterate: Your data is not shared with anyone else. It is stored only on the device from which you use Photrax." TextWrapping="Wrap" FontSize="26" FontFamily="Verdana">
</TextBlock>
</Flyout>
</StackPanel>
</AppBarButton.Flyout>
</AppBarButton>
...which fails with, "The property "Content" can only be set once."
Why is there a problem with this, when the following XAML, which is basically the same, compiles fine:
<AppBarButton Icon="MapPin" Label="Colors In Use" Tapped="appbarbtnPhotosetColorMapping_Tapped">
<AppBarButton.Flyout>
<Flyout>
<StackPanel Background="Azure">
<TextBlock Text="Photoset:Pushpin Color Legend" TextWrapping="Wrap" FontSize="26" FontFamily="Verdana"></TextBlock>
<TextBlock x:Name="textblock0" Text="Unused" Foreground="Red" FontFamily="Segoe UI" FontSize="13" Margin="4" />
. . .
?
I get other err msgs with that xaml, too (about the following types being expected: flyoutbase and uielement), but I think it's the Content business that is giving me the business.
I pasted the problem code into kaxaml, but it doesn't even know what an AppBarButton is, and complained about that being an invalid element.
UPDATE
I can't test it yet, but I'm thinking that what Abdallah means is that I need to change this:
<StackPanel>
<Flyout>
. . .
</Flyout>
</StackPanel>
...to this:
<Flyout>
<StackPanel>
. . .
</StackPanel>
</Flyout>
You have two problems here :
1) The property "Content" can only be set once. :
You can't set the content for <Flyout> </Flyout> more than once and you set the content twice (Two TextBlocks) in first XAML code and in the working XAML once(One StackPanel), According to MSDN :
<Flyout>
singleUIElement
</Flyout>
singleUIElement :
A single object element that declares the content. This must be an
object that has UIElement in its hierarchy (plain strings don't work).
This can be a container, such as a Panel derived class, so that
multiple content items within the Flyout can be arranged in layout.
2) The following type was expected: "FlyoutBase".
You can't set Flyout property to any class that not derived from FlyoutBase class (i.e only Flyout and MenuFlyout ). you set the Flyout property in first XAML code to StackPanel and in the working XAML to Flyout .
I am attempting to use a Telerik RadDataBoundListBox with a custom ItemTemplate. However, when I attempt to set the DataTemplate I receive an Invalid XAML exception and can no longer compile. Should I be using Styles?
<telerikPrimitives:RadDataBoundListBox Grid.Row="1">
<telerikPrimitives:RadDataBoundListBox.ItemTemplate>
<DataTemplate>
<telerikPrimitives:RadHubTile/>
</DataTemplate>
</telerikPrimitives:RadDataBoundListBox.ItemTemplate>
</telerikPrimitives:RadDataBoundListBox>
This error occurs no matter what is inside the DataTemplate tags.