Click here to Skip to main content
15,910,234 members
Home / Discussions / WPF
   

WPF

 
QuestionDetection of physical keyboard on Windows 7 in a desktop WPF application Pin
Jenny D30-May-14 12:04
Jenny D30-May-14 12:04 
AnswerRe: Detection of physical keyboard on Windows 7 in a desktop WPF application Pin
Bernhard Hiller2-Jun-14 0:20
Bernhard Hiller2-Jun-14 0:20 
GeneralRe: Detection of physical keyboard on Windows 7 in a desktop WPF application Pin
Jenny D4-Jun-14 11:49
Jenny D4-Jun-14 11:49 
QuestionMediaElement not releasing the file on its Close() method in WPF Pin
Praveen Raghuvanshi28-May-14 17:59
professionalPraveen Raghuvanshi28-May-14 17:59 
AnswerRe: MediaElement not releasing the file on its Close() method in WPF Pin
Gerry Schmitz29-May-14 10:40
mveGerry Schmitz29-May-14 10:40 
GeneralRe: MediaElement not releasing the file on its Close() method in WPF Pin
Praveen Raghuvanshi3-Jun-14 23:55
professionalPraveen Raghuvanshi3-Jun-14 23:55 
QuestionCombobox - Highlights first letter typed after gained focus Pin
Clint Dow27-May-14 7:49
Clint Dow27-May-14 7:49 
QuestionDisplay Alternative images based on AlternationCount=2 in listbox in wpf application ..its not Displaying Pin
Member 785476927-May-14 0:46
Member 785476927-May-14 0:46 
QuestionMake a 3D casino spin wheel in Silverlight. Pin
Vishal Kumar Singh26-May-14 23:17
Vishal Kumar Singh26-May-14 23:17 
AnswerRe: Make a 3D casino spin wheel in Silverlight. Pin
amigoface27-May-14 2:16
amigoface27-May-14 2:16 
Questionhow to drag and drop with image preview in wpf using c# Pin
kalsa23-May-14 21:20
kalsa23-May-14 21:20 
QuestionBest Practice for using WPF Resources Pin
hari111r19-May-14 19:14
hari111r19-May-14 19:14 
AnswerRe: Best Practice for using WPF Resources Pin
Mycroft Holmes19-May-14 21:22
professionalMycroft Holmes19-May-14 21:22 
GeneralRe: Best Practice for using WPF Resources Pin
hari111r19-May-14 23:52
hari111r19-May-14 23:52 
GeneralRe: Best Practice for using WPF Resources Pin
Mycroft Holmes20-May-14 13:02
professionalMycroft Holmes20-May-14 13:02 
QuestionTwo questions about the TreeView control Pin
Mc_Topaz16-May-14 1:45
Mc_Topaz16-May-14 1:45 
Hi!

I have a WpfApplication with a TreeView and a Button.
XML
<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfApplication1"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <TreeView Name="tvTree">
            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding List}" DataType="{x:Type local:BaseNode}">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Header}" />
                    </StackPanel>
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
        </TreeView>
        <Button Width="20" Height="20" Content="Click" Click="Button_Click" />
    </Grid>
</Window>

The TreeView's ItemsSource property will be populated from a list based on the BaseNode class. That class look like this:
C#
public class BaseNode
{
    System.Collections.ObjectModel.ObservableCollection<BaseNode> list = new System.Collections.ObjectModel.ObservableCollection<BaseNode>();

    string header;

    public BaseNode(string header)
    {
        this.header = header;
    }

    public string Header
    {
        get { return header; }
        set { header = value; }
    }

    public System.Collections.ObjectModel.ObservableCollection<BaseNode> List
    {
        get { return list; }
        set { list = value; }
    }
}
The MainWindow.cs have this code:
C#
public partial class MainWindow : Window
{
    BaseNode a = new BaseNode("Base");
    BaseNode b = new BaseNode("Sub1");
    BaseNode c = new BaseNode("Sub2");
    BaseNode ba = new BaseNode("Sub1Sub1");
    BaseNode baa = new BaseNode("Sub1Sub1Sub1");

    public MainWindow()
    {
        InitializeComponent();

        a.List.Add(b);
        a.List.Add(c);
        b.List.Add(ba);
        ba.List.Add(baa);
        tvTree.ItemsSource = a.List;
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        b.Header = "NewHeader";
    }
}

Question 1:
When I click the button I would like to change the Header property of one of the BaseNodes. But the code for the Button.Click event won't do the trick. Just setting the BaseNode.Header property seem not to be enough. Instead I need to alter the Button.Click callback to:
C#
private void Button_Click(object sender, RoutedEventArgs e)
{
    b.Header = "NewHeader";
    tvTree.ItemsSource = null;
    tvTree.ItemsSource = a.List;
}

This does the job but seem to be very overkill for such a small thing.

Is there a better way to make the TreeView show the new value of the BaseNode.Header property?




Question 2:
Image I have populated the same TreeView with a bunch of BaseNode objects forming a tree with many branches of BaseNodes as well as branches in branches. I lack a way to, manually by code, open or close a branch in the TreeView.

I have found out that this is supported for the TreeViewItem control which have the IsExpanded property. My BaseNode class don't have such a property and including one I highly doubt it will "solve the problem".

With the TreeView.SelectedItemChanged event I can select any BaseNode in the TreeView and find out the actual BaseNode instance I selected. From this point I would like to be able to open or close the nested BaseNodes.

How to open or close a nested node in the TreeView which is not a TreeViewItem?

Best regards
/Mc_Topaz
AnswerRe: Two questions about the TreeView control Pin
SledgeHammer0116-May-14 6:45
SledgeHammer0116-May-14 6:45 
QuestionRe: Two questions about the TreeView control Pin
Mc_Topaz16-May-14 7:40
Mc_Topaz16-May-14 7:40 
AnswerRe: Two questions about the TreeView control Pin
SledgeHammer0116-May-14 8:16
SledgeHammer0116-May-14 8:16 
GeneralRe: Two questions about the TreeView control Pin
Mc_Topaz16-May-14 9:08
Mc_Topaz16-May-14 9:08 
QuestionOCR using Microsoft Office Document Imaging 12.0 Type Library in WPF application Pin
Member 785476914-May-14 20:20
Member 785476914-May-14 20:20 
AnswerRe: OCR using Microsoft Office Document Imaging 12.0 Type Library in WPF application Pin
AlphaDeltaTheta15-May-14 16:48
AlphaDeltaTheta15-May-14 16:48 
QuestionSilverlight: Exception with ListBox and nested collection Pin
tongo7612-May-14 23:01
tongo7612-May-14 23:01 
AnswerRe: Silverlight: Exception with ListBox and nested collection Pin
Mycroft Holmes13-May-14 12:56
professionalMycroft Holmes13-May-14 12:56 
QuestionWPF Generate Dynamic Messages Including Links Pin
Kevin Marois6-May-14 16:44
professionalKevin Marois6-May-14 16:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.