Access component in style of ListboxItem
Posted: 23 May 2014, 18:23
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"));