0

I download a sample code from here http://www.codeproject.com/Articles/28306/Working-with-Checkboxes-in-the-WPF-TreeView

The sample code works fine. My questions is that I want to make this part of xaml into C# code.

  <Window.Resources>
    <ResourceDictionary>
      <!-- Load this specific theme because the Aero theme for CheckBox has issues. -->


      <Style x:Key="TreeViewItemStyle" TargetType="TreeViewItem">
        <Setter Property="IsExpanded" Value="True" />
        <Setter Property="IsSelected" Value="{Binding IsInitiallySelected, Mode=OneTime}" />
        <Setter Property="KeyboardNavigation.AcceptsReturn" Value="True" />
        <Setter Property="dw:VirtualToggleButton.IsVirtualToggleButton" Value="True" />
        <Setter Property="dw:VirtualToggleButton.IsChecked" Value="{Binding IsChecked}" />        
      </Style>

      <HierarchicalDataTemplate 
        x:Key="CheckBoxItemTemplate"
        ItemsSource="{Binding Children, Mode=OneTime}"
        >
        <StackPanel Orientation="Horizontal">
          <!-- These elements are bound to a FooViewModel object. -->
          <CheckBox
            Focusable="False" 
            IsChecked="{Binding IsChecked}" 
            VerticalAlignment="Center"
            />
          <ContentPresenter 
            Content="{Binding Name, Mode=OneTime}" 
            Margin="2,0"
            />
        </StackPanel>
      </HierarchicalDataTemplate>
    </ResourceDictionary>
  </Window.Resources>

Can anyone tell me how to do that? Thanks,

3
  • 1
    You can do that as explained here stackoverflow.com/questions/4990624/wpf-add-controls-from-code . Out of my curiosity, may I ask why you wan't to do that ? Commented May 25, 2013 at 4:41
  • if you need to use these in cs code, you don't need to port them to cs, you can just resolve the resource in cs. It' be much easier to maintain markup code in XAML Commented May 25, 2013 at 14:16
  • Thanks for the reply. I am trying to combine Thanks for the reply. I am trying to combine the VirtualToggleButton class and FooViewModel into a custom control. Commented May 28, 2013 at 17:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.