- vaninadisc
- Posts: 10
- Joined:
Having trouble getting Converters to work within ItemsControl...
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!
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Having trouble getting Converters to work within ItemsControl...
I think it is a problem with types. The converter probably expects a float (please check targetType parameter), and you are returning an integer.
We should probably show that as an error in the Unity console.
Could you please try to return 200.0f instead and let me know?
We should probably show that as an error in the Unity console.
Could you please try to return 200.0f instead and let me know?
- vaninadisc
- Posts: 10
- Joined:
Re: Having trouble getting Converters to work within ItemsControl...
Ah, Yep! That was it. Thank you very much. I see how it's my fault, but yes, an error message for this would be great, it'd be so easy to accidentally not to a final cast at the end even if I was checking the type.
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Having trouble getting Converters to work within ItemsControl...
Could you please report it in our bugtracker, this way is better to keep track of bugs and missing features.yes, an error message for this would be great, it'd be so easy to accidentally not to a final cast at the end even if I was checking the type
Who is online
Users browsing this forum: No registered users and 12 guests