Context: I'm writing a UWP Twitter client. One of the properties of my Tweet class is a bool called IsRetweet
- if the tweet contains a retweet, this is set to True.
I want to use this with x:Load
in order to conditionally load an extra row in my UI that displays "@username retweeted".
I'm going off this example: https://learn.microsoft.com/en-us/windows/uwp/xaml-platform/x-load-attribute
And here's my XAML, which is inside a ResourceDictionary:
<Grid Grid.Row="0" x:Name="RetweetedBy" x:Load="{x:Bind (x:Boolean)IsRetweet, Converter={StaticResource DebugThis}}">
<StackPanel Orientation="Horizontal" Padding="4 8 4 0">
<StackPanel.Resources>
<Style TargetType="TextBlock">
<Setter Property="FontSize" Value="12"/>
<Setter Property="Foreground" Value="{ThemeResource SystemControlPageTextBaseMediumBrush}" />
</Style>
</StackPanel.Resources>
<Border Height="28">
<TextBlock Height="24" FontFamily="{StaticResource FontAwesome}" xml:space="preserve"><Run Text=" "/></TextBlock>
</Border>
<TextBlock Text="{Binding Path=User.Name}" />
<TextBlock Text=" retweeted"/>
</StackPanel>
</Grid>
I added a temporary converter called DebugThis to the field I'm binding for x:Load, which looks like this:
public class DebugThis : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
bool IsRetweet = (bool)value;
return IsRetweet;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
I stuck a breakpoint on this, and I'm not even hitting the converter, so I'm guessing something is wrong with my XAML binding. I've triple-checked the objects that use this DataTemplate, and each object definitely has the IsRetweet
property set correctly.
ETA: I'm able to get x:Bind
to load bound data by adding this to my UI page's XAML:
<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<tweeter:Visuals />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Page.Resources>
However, now if I load new content into the UI dynamically, x:Bind
bindings aren't rendering.