Having trouble getting Converters to work within ItemsControl...
Posted: 10 Nov 2017, 18:39
On Unity 2017.1.0f3 and Noesis 2.1.0b4...
I'm having trouble to get Converters to work in an item control. In the code below, I'm just trying to be able to bind the Canvas.Left of the item to something in it's datasource, through a Converter.
For the 3 lines that are commented out-
#1 works as expected.
#2 works as expected.
#3 does not work. BUT, I can tell that the converter code is being called, because my (for debugging) converter is:
and the debug message is getting printed. However, it appears as if Canvas.Left is just getting set to 0. It's definitely not at 200.
Any help would be appreciated, not sure what I'm doing wrong. For reference, the converter's goal (not yet implemented) will be to go from the avatar's position in viewport space, to the space that Noesis works in, I guess scaled off the canvas size. I'm more than happy to take suggestions of better ways to do this while I'm here, but I'm going to need converters working like this in an itemscontrol anyhow.
Thanks!
I'm having trouble to get Converters to work in an item control. In the code below, I'm just trying to be able to bind the Canvas.Left of the item to something in it's datasource, through a Converter.
Code: Select all
<ItemsControl ItemsSource="{Binding PrimaryAvatarBarsToDisplay}">
<ItemsControl.Resources>
<dgx:WorldTopToPointConverter x:Key="WorldTopPositionConverter" />
</ItemsControl.Resources>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas Grid.ColumnSpan="2" Grid.RowSpan="2" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<!-- 1. <Setter Property="Canvas.Left" Value="150" /> -->
<!-- 2. <Setter Property="Canvas.Left" Value="{Binding WorldLeftPosition}" /> -->
<!-- 3. <Setter Property="Canvas.Left" Value="{Binding WorldLeftPosition, Converter={StaticResource ResourceKey="WorldLeftPositionConverter"} /> -->
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate>
<dgx:PrimaryAvatarHealthBar />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
#1 works as expected.
#2 works as expected.
#3 does not work. BUT, I can tell that the converter code is being called, because my (for debugging) converter is:
Code: Select all
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Debug.Log("Converting " + value);
return 200;
}
Any help would be appreciated, not sure what I'm doing wrong. For reference, the converter's goal (not yet implemented) will be to go from the avatar's position in viewport space, to the space that Noesis works in, I guess scaled off the canvas size. I'm more than happy to take suggestions of better ways to do this while I'm here, but I'm going to need converters working like this in an itemscontrol anyhow.
Thanks!