how can i define a global button and use it in multiple places in WPF.
here is my button witch i want to use it in multiple places.
<Button x:Key="Attach" Width="90" Margin="220,0,0,0" Content="Attach" Height="16" FontSize="11"/>
however i tried to define it in App.xaml
(Application.Resources
)
and also in MainWindow.xaml
(inside Window.Resources
)
But i cannot access it in CodeBehind
Button button = Resources["Attach"];
My question is where to define my button
and if i defined it correct how to use it in CodeBehind and XAML.
In your MainWindow.xaml
Defining a
HiercharchicalDataTemplate
with your button layout will allow you to re-use it as anItemTemplate
in your TreeView:As you see I'm making intensive use of binding for resources as well as data because I'm building my wpf/sl apps the MVVM way. Doing so makes the need to access controls from code behind obsolete and might be worth looking into for you.