-
- noesis_user
- Posts: 14
- Joined:
Access component in style of ListboxItem
Hello,
I am applying a style to listbox item and then adding it to listbox. style is:(shorter version for
convenience)
Applying style to listbox:
Getting button:
But it always returns NULL. Any pointers ?
I am applying a style to listbox item and then adding it to listbox. style is:(shorter version for
convenience)
Code: Select all
<Style x:Key="ListBoxItemStyle" TargetType="{x:Type ListBoxItem}">
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Grid x:Name="GridListItem" Height="Auto" Focusable="True">
<Button x:Name="ButtonDelete" Content="Button"
HorizontalAlignment="Right" Height="Auto" Margin="0"
Style="{DynamicResource DeleteButtonStyle}"
VerticalAlignment="Stretch" Width="25" Visibility="Visible"
IsHitTestVisible="True" Focusable="True"/>
<Path Data="M40.5,25.5 L188.50084,25.5" Fill="#00BCCFEA" Height="Auto"
Stretch="Fill" Stroke="#FF556285" Width="Auto" Margin="0"
VerticalAlignment="Bottom"/>
</Grid>
</ControlTemplate>
</Style>
Code: Select all
Ptr<IResourceKey> key = ResourceKeyString::Create("ListBoxItemStyle");
temp_ = p1_root->FindResource<Noesis::Gui::Style>(key.GetPtr());
list_box_->SetItemContainerStyle(temp_);
Code: Select all
int index = list_box_->GetSelectedIndex();
Noesis::Gui::FrameworkElement* l = NsStaticCast<Noesis::Gui::FrameworkElement*>
(list_box_->GetItems()->Get(index));
Noesis::Gui::Button* b1 = NsStaticCast<Noesis::Gui::Button*>(l->GetTemplateChild("ButtonDelete"));
-
-
sfernandez
Site Admin
- Posts: 3203
- Joined:
Re: Access component in style of ListboxItem
How do you provide the items to the ListBox?
Are you using the ItemsSource property?
Or are you adding the items yourself via GetItems().Add()?
Which type of item are you adding?
Remember that the GetItem() return the item instance, that is not always the ListBoxItem container. And you have to invoke the GetTemplateChild() function over the ListBoxItem to find that button you are looking for.
Are you using the ItemsSource property?
Or are you adding the items yourself via GetItems().Add()?
Which type of item are you adding?
Remember that the GetItem() return the item instance, that is not always the ListBoxItem container. And you have to invoke the GetTemplateChild() function over the ListBoxItem to find that button you are looking for.
Who is online
Users browsing this forum: No registered users and 6 guests