-
- David Jefferies
- Posts: 27
- Joined:
Only a single instance of a CroppedBitmap visible in an ItemsControl
We have an issue which we think is similar to this one:
viewtopic.php?t=1951
In our case the image is a CroppedBitmap from an atlas
and we have a custom ContentControl with a style:
Only one instance of an image ever gets displayed in the ItemsControl
Is there a workaround for this use case?
viewtopic.php?t=1951
In our case the image is a CroppedBitmap from an atlas
Code: Select all
<CroppedBitmap x:Key="T_HUD_icon_button_KBD_mouse" Source="{StaticResource T_HUD_atlas_main}" SourceRect="573,977,64,64"/>Code: Select all
<Style x:Key="InputActionControl-Style" TargetType="{x:Type ctrl:InputActionControl}" BasedOn="{StaticResource BaseUnfocusable-Style}">
<Setter Property="Template" Value="{StaticResource InputActionControl-Template}"/>
<Setter Property="Content" Value="{x:Null}"/>
<Style.Triggers>
<Trigger Property="InputAssetPath" Value="Keyboard_Mouse2D">
<Setter Property="Tag" Value="True"/>
<Setter Property="Content">
<Setter.Value>
<Rectangle HorizontalAlignment="Center" Height="32" VerticalAlignment="Center" Width="32">
<Rectangle.Fill>
<ImageBrush ImageSource="{StaticResource T_HUD_icon_button_KBD_mouse}"/>
</Rectangle.Fill>
</Rectangle>
</Setter.Value>
</Setter>
</Trigger>
...
...
</Style.Triggers>
</Style>Is there a workaround for this use case?
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Only a single instance of a CroppedBitmap visible in an ItemsControl
Hi David,
The problem is that you are setting the Content from the Style, so the same Rectangle is being set on each of the items.
You must be getting the error message "Child already has a logical parent" for all the items but the first one.
I guess you want to define that Rectangle as part of the control template and just set the ImageSource as Content:
Could that work for you?
The problem is that you are setting the Content from the Style, so the same Rectangle is being set on each of the items.
You must be getting the error message "Child already has a logical parent" for all the items but the first one.
I guess you want to define that Rectangle as part of the control template and just set the ImageSource as Content:
Code: Select all
<ControlTemplate x:Key="InputActionControl-Template" TargetType="{x:Type ctrl:InputActionControl}">
...
<Rectangle Height="32" Width="32">
<Rectangle.Fill>
<ImageBrush ImageSource="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}"/>
</Rectangle.Fill>
</Rectangle>
...
</ControlTemplate>Code: Select all
<Style x:Key="InputActionControl-Style" TargetType="{x:Type ctrl:InputActionControl}" BasedOn="{StaticResource BaseUnfocusable-Style}">
<Setter Property="Template" Value="{StaticResource InputActionControl-Template}"/>
...
<Style.Triggers>
<Trigger Property="InputAssetPath" Value="Keyboard_Mouse2D">
<Setter Property="Content" Value="{StaticResource T_HUD_icon_button_KBD_mouse}"/>
</Trigger>
...
</Style.Triggers>
</Style>-
- David Jefferies
- Posts: 27
- Joined:
Re: Only a single instance of a CroppedBitmap visible in an ItemsControl
yes that works - thanks!
Who is online
Users browsing this forum: Bing [Bot] and 3 guests