|
I have a treeview with a Template
The treeviewitem has an event handler. I want to access the parent treeviewitem from here. How can I achieve this.
End Goal - User can select a node and delete it.
Template
<br />
<sdk:HierarchicalDataTemplate x:Key="TreeViewMainReadTemplate" ItemsSource="{Binding Children}"><br />
<TextBlock Text="{Binding Text,Mode=TwoWay}" <br />
MouseLeftButtonDown="TreeViewMain_MouseLeftButtonDown"></TextBlock><br />
</sdk:HierarchicalDataTemplate><br />
TreeView
<br />
<sdk:TreeView Name="TreeViewMain" <br />
ItemTemplate="{StaticResource TreeViewMainReadTemplate}" <br />
Width="400" Height="400" ><br />
</sdk:TreeView><br />
Event Handler Where I want to access parent
<br />
private void TreeViewMain_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)<br />
{<br />
}<br />
Binding Data Class
<br />
public class Node<br />
{<br />
private String text;<br />
private ObservableCollection<Node> children;<br />
public ObservableCollection<Node> Children<br />
{<br />
get{ return children;}<br />
set{ children = value;}<br />
}<br />
<br />
public String Text { get { return text; } set { text = value; } }<br />
<br />
public Node(String text)<br />
{<br />
Children = new ObservableCollection<Node>();<br />
Text = text;<br />
}<br />
<br />
public void Add(Node node)<br />
{<br />
children.Add(node); <br />
NotifyPropertyChanged("Children");<br />
}<br />
<br />
public void Delete(Node node)<br />
{<br />
children.Remove(node);<br />
NotifyPropertyChanged("Children");<br />
}<br />
<br />
public event PropertyChangedEventHandler PropertyChanged;<br />
<br />
private void NotifyPropertyChanged(String info)<br />
{<br />
if (PropertyChanged != null)<br />
{<br />
PropertyChanged(this, new PropertyChangedEventArgs(info));<br />
}<br />
}<br />
}<br />
|
|
|
|
|
'sender' should be your Node object. You can then do something like:
Node node = sender as Node;
TreeViewItem tvi = ItemContainerGenerator.ContainerFromItem(node) as TreeViewItem;
You need to be careful here though because the WPF treeview is virtualized, so the TreeViewItem objects come and go as you scroll, collapse, etc. Its possible that ItemContainerGenerator.ContainerFromItem(node) will return null.
|
|
|
|
|
Thanks SledgeHammer01
I was just able to do this using TreeViewExtension part of the silverlight tookit.
TreeViewItem selectedTreeViewItem =
TreeViewExtensions.GetContainerFromItem(TreeViewMain, selectedNode);
if (selectedTreeViewItem != null)
{
TreeViewItem selectedTreeViewItemParent =
TreeViewExtensions.GetParentTreeViewItem(selectedTreeViewItem);
Also thankyou for your suggestions about binding the treeview data. I am doing that, and my life's much easier
|
|
|
|
|
Apologiese.
Wrong post.
modified on Monday, January 17, 2011 9:24 AM
|
|
|
|
|
And what does any of this have to do with Silverlight or WPF?
|
|
|
|
|
Yes you are right.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
|
|
|
|
|
[EDIT]Issue below is solved. Somehow, for some reason, the properties indicating the binding needed to be in uppercase. I was under the impression that oracle was caseINsensative on this point? If anyone can elaborate, please do, because honestly, I don't understand.
[/EDIT]
I have a listview which ItemsSource is set from a dataset. I verified its contents and affter the assigment this property has the correct values.
In my XAML I then defined the GridViewColumns by binding the object-properties to the corresponding column in the grid. A prototype with MS Access worked perfectly. Now we moved to Oracle and changed one column from string to a datetime. To tackle this, I made a valueconverter.
Problem is, for some reason, the grid stays empty. No errors. the Items.Count shows there are items, but they don't show up in the grid. I can also select each row. In addition a breakpoint in the valueconverters classes don't break for some reason.
I'm pretty sure it's or the valueconverter or the XAML that's wrong, but after staring at it for 2 hours and googling I couldn't find my problem.
Does someone recognize this issue (it must be something small and stupid I'm overlooking)? Many thanks !
here's the XAML code:
<ListView Name="lv_logs" ItemsSource="{Binding}" FontSize="12">
<ListView.View>
<GridView>
<GridViewColumn Header="DateTime">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock VerticalAlignment="Center" Margin="5,0,0,0" Text="{Binding Path=logdts, Converter={StaticResource dts_valueconverter}}"></TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Type">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Path=logtype, Converter={StaticResource logtype_valueconverter}}" Height="20" Width="20"/>
<TextBlock VerticalAlignment="Center" Margin="5,0,0,0" Text="{Binding Path=logtype}"></TextBlock>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Actor">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Path=logactor, Converter={StaticResource logactor_valueconverter}}" Height="20" Width="20"/>
<TextBlock VerticalAlignment="Center" Margin="5,0,0,0" Text="{Binding Path=logactor}"></TextBlock>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Application" DisplayMemberBinding="{Binding Path=logmodule}"></GridViewColumn>
<GridViewColumn Header="Machine" DisplayMemberBinding="{Binding Path=logmachine}"></GridViewColumn>
<GridViewColumn Header="Message" DisplayMemberBinding="{Binding Path=logmessage}"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
V.
modified on Monday, January 17, 2011 8:07 AM
|
|
|
|
|
Hi i need some help, my styling is not working a i would like it to.
on the x axis that i try to style i have 4 text´s that says "good", "poor" etc...
The problem is that after i apply the style and change the angel of the text change to about 10 different values 0 and 1
(there are still 4 columnbars displayed)
I want the text good to be at an angle of -64
and adjust the with of the bars to make them smaller
EDIT: The independentvalue bindings displays at the top of the graph, the bottom displays values from 0, 0,1 0,2 0,3 ... 1
can anyone help?
<chartingToolkit:Chart HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
BorderBrush="White"
x:Name="Chart"
FlowDirection="LeftToRight"
Margin="6,1,1,1"
Grid.Column="0"
Grid.Row="0"
Title="Score"
FontFamily="Arial"
FontSize="10.667"
BorderThickness="0,1,1,1">
<chartingToolkit:Chart.LegendStyle>
<Style TargetType="Control">
<Setter Property="Width"
Value="0" />
<Setter Property="Height"
Value="0" />
</Style>
</chartingToolkit:Chart.LegendStyle>
<chartingToolkit:Chart.Axes>
<chartingToolkit:LinearAxis Orientation="X">
<chartingToolkit:LinearAxis.AxisLabelStyle>
<Style TargetType="chartingToolkit:AxisLabel">
<Setter Property="RenderTransformOrigin"
Value="0.8,0.8" />
<Setter Property="RenderTransform">
<Setter.Value>
<RotateTransform Angle="-65" />
</Setter.Value>
</Setter>
</Style>
</chartingToolkit:LinearAxis.AxisLabelStyle>
</chartingToolkit:LinearAxis>
</chartingToolkit:Chart.Axes>
<chartingToolkit:ColumnSeries x:Name="ScoringColumn"
IndependentValueBinding="{Binding Scoring}"
DependentValueBinding="{Binding Number}"
Title="Series 1" />
</chartingToolkit:Chart>
modified on Monday, January 17, 2011 6:07 AM
|
|
|
|
|
I got it working, i replaced LinearAxis with CategoryAxis.
|
|
|
|
|
Hello,
When i wrote a "Source" property as full path "C:\aaa\aaa\aaa\aa\fileName" i do hear the sound, but when i'm trying to set the path using the resources, it doesn't work (no sound), i've marked build actions of the media file as "resources". and in source i wrote /namespace;component/Resources/filename
What i'm doing wrong here ?
thanks
|
|
|
|
|
|
omeriko9 wrote: Otherwise use the "Content" build action and access it as you suggested.
you mean by /UIapp;component/Resources ... didn't work still no sound
|
|
|
|
|
No that's not what I mean.
I mean that you CAN'T use Pack Uri for MediaElement.Source, therefor any syntax of Pack Uri you'll use won't work.
If you still wish to embed the wave/mp3 file as a resource, please re-read my previous answer for a workaround.
Thanks
Omer
|
|
|
|
|
just to make it clear,
you wrote "as you suggested"
what I suggested ?
the URI way, and the full path name way
|
|
|
|
|
"as you suggested" means NOT embedding the sound file in the assembly by using build action "content" and "copy if newer", and setting the Source property to a full or relative path, as your first attempt.
e.g.: \Soundfiles\myfile.wav
|
|
|
|
|
Hello,
At present I have visual web developer 2010 express which I use for silverlight development.
Now I would like to instal the visual c# 2010 express for WPF development.
During the install I get the following error:
The following component could not be downloaded:
.net framework 4 multi-targeting pack
Any thoughts on how to solve this please?
|
|
|
|
|
|
Try installing .Net framework 4 before you try to install C# 2010 express.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
|
|
|
|
|
Hi!
i have a problem with ContentStringFormat
i get an error
The property 'ContentStringFormat' does not exist on the type 'ContentControl' in the XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'.
The example i follow uses this namespace,
is there an other namespace i should use? Why do i get this error?
<UserControl
...
...
...
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<StackPanel Margin="2,2,2,2">
<ContentControl Content="{TemplateBinding IndependentValue}"
ContentStringFormat="{}{0:MMMM d, yyyy}" />
<ContentControl Content="{TemplateBinding DependentValue}"
ContentStringFormat="Visits {0:###,###,###}" />
</StackPanel>
|
|
|
|
|
Is your project targeting the .NET 3.5 (SP1) or .NET 4 runtime? If you are using VS2008 and the plain vanilla .NET 3.5, you won't see this property as it was added in .NET 3.5 SP1.
|
|
|
|
|
Hi!
i use VS2010, and the SL project targets Silverlight 4 and .Net 4
|
|
|
|
|
You should have said in your post that it was Silverlight rather than WPF. AFAIK, Silverlight does not support ContentControl.ContentStringFormat . This is a WPF feature.
|
|
|
|
|
|
I like the MVVM pattern and I have been keeping code in the ViewModel class. However, one thing is kicking my ass! When I make a mistake and the result of the databinding is not what I expect, I have no idea how to figure out what the hell is wrong! How do I debug xaml bidings?
-- Modified Thursday, January 13, 2011 9:29 PM
|
|
|
|
|
The output window looks ot be your best bet!
Very nice article here[^].
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
|
|
|
|