|
Hi there,
I am quite new to C# and WPF especially. I have a form, with 2 listboxes on. The first looks up an xml file and gets some data items (themes), the next listbox is bound to the first, and gets some data (scenes) from inside the selected theme tag.
This works wonderfully.
I would now like to get the value of an element (FreeStyleCue) and use that in a c# function tied to the OnSelectionChanged handler.
However I cant work out for the life of me how to get the information from the FreeStyleCue tag.
Can anyone help me??
Here is the xml file.
<?xml version="1.0" encoding="utf-8" ?><br />
<themes><br />
<theme name="Yellow" description="A yellow theme" order="1"><br />
<scene name="PreShow" order ="1"><br />
<description>For before the show yellow.</description><br />
<FreeStyleCue>y12</FreeStyleCue><br />
</scene><br />
<scene name="Scenex" order ="1"><br />
<description>During yellow show</description><br />
<FreeStyleCue>y122</FreeStyleCue><br />
</scene><br />
</theme><br />
<theme name="Blue" description="A blue theme" order="1"><br />
<scene name="PreShow" order ="1"><br />
<description>For before the show</description><br />
<FreeStyleCue>b12</FreeStyleCue><br />
</scene><br />
<scene name="Scene1" order ="1"><br />
<description>During Show</description><br />
<FreeStyleCue>b122</FreeStyleCue><br />
</scene><br />
</theme><br />
</themes><br />
Here is the WPF XAML file
<Window x:Class="WpfApplication1.Window1"<br />
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"<br />
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"<br />
Title="Window1" Height="400" Width="800"><br />
<Window.Resources><br />
<br />
<XmlDataProvider x:Key="AllThemes" XPath="themes" Source="testdata.xml" /><br />
<br />
<br />
<DataTemplate x:Key="dtThemes"><br />
<br />
<StackPanel FlowDirection="LeftToRight" Orientation="Vertical"><br />
<br />
<TextBlock Text="{Binding XPath=@name}" FontSize="15" /><br />
<TextBlock Text="{Binding XPath=@description}" /><br />
<br />
</StackPanel><br />
<br />
</DataTemplate><br />
<br />
<br />
<DataTemplate x:Key="dtScenes"><br />
<StackPanel FlowDirection="LeftToRight" Orientation="Vertical"><br />
<br />
<TextBlock Text="{Binding XPath=@name}" FontSize="15" /><br />
<TextBlock Text="{Binding XPath=description}" /><br />
<TextBlock Text="{Binding XPath=FreeStyleCue}" /><br />
<br />
</StackPanel><br />
</DataTemplate><br />
<br />
<br />
<br />
</Window.Resources><br />
<br />
<br />
<br />
<Grid Name="gMain"><br />
<Grid.ColumnDefinitions><br />
<ColumnDefinition Width="123" /><br />
<ColumnDefinition Width="8"/><br />
<ColumnDefinition Width="*" /><br />
</Grid.ColumnDefinitions><br />
<br />
<Menu Grid.Column="0" Grid.ColumnSpan="3"></Menu><br />
<br />
<ListBox Name="listboxTheme" <br />
ItemsSource="{Binding Source={StaticResource AllThemes}, XPath=theme}"<br />
ItemTemplate="{StaticResource dtThemes}" HorizontalAlignment="Left" Width="123"><br />
</ListBox><br />
<br />
<GridSplitter Grid.Column="1"></GridSplitter><br />
<br />
<StackPanel Grid.ColumnSpan="2" Margin="6,0,6,0" Grid.Column="1"><br />
<ListBox Name="listboxScenes" <br />
ItemsSource="{Binding ElementName=listboxTheme, Path=SelectedItem, UpdateSourceTrigger=PropertyChanged}" <br />
ItemTemplate="{StaticResource dtScenes}" Height="650" SelectionChanged="listboxScenes_SelectionChanged"><br />
<br />
</ListBox><br />
</StackPanel><br />
<br />
</Grid><br />
</Window><br />
and the code that is asking for the data
<br />
private void listboxScenes_SelectionChanged(object sender, SelectionChangedEventArgs e)<br />
{<br />
<br />
<br />
SelectQueueInFS(SelectionID);
}<br />
<br />
|
|
|
|
|
I give u an example.
I have a ComboBox 'themesComboBox' decalared in XAML file. (Note the x:Name, instead of Name, so that we can refer the ComboBox from C#).
<ComboBox SelectedIndex="0" x:Name="themesComboBox" SelectionChanged="ThemeChanged">
The following is the method which handles the event.
void ThemeChanged(object sender,RoutedEventArgs args)
{
ComboBoxItem cbi =(ComboBoxItem)themesComboBox.SelectedItem;
string themeName = cbi.Content.ToString();
}
Modify the two lines in your program
<TextBlock Text="{Binding XPath=FreeStyleCue}" /> to
<TextBlock Text="{Binding XPath=FreeStyleCue}" x:Name='freeStyeleCueTextBox'/>
<ListBox Name="listboxScenes"
ItemsSource="{Binding ElementName=listboxTheme, Path=SelectedItem, UpdateSourceTrigger=PropertyChanged}"
ItemTemplate="{StaticResource dtScenes}" Height="650" SelectionChanged="listboxScenes_SelectionChanged"> to
<ListBox x:Name="listboxScenes"
ItemsSource="{Binding ElementName=listboxTheme, Path=SelectedItem, UpdateSourceTrigger=PropertyChanged}"
ItemTemplate="{StaticResource dtScenes}" Height="650" SelectionChanged="listboxScenes_SelectionChanged">
Now you can access the textbox and list box from your c# code.
Hope it will help you.
|
|
|
|
|
Hi there,
Thanks for the help. Most appreciated!
THe only thing is that I was using XML in the listbox so it outputs XML instead of a string.
I have included
using System.Xml;
and then the code is now
XmlNodeList FSQUES = ((XmlElement)listboxScenes.SelectedItem).GetElementsByTagName("FreeStyleCue");<br />
<br />
foreach (XmlNode FreeStyleCue in FSQUES)<br />
{<br />
SelectQueueInFS(FreeStyleCue.InnerText);<br />
<br />
}
Hope this helps someone.
Reg
|
|
|
|
|
Hi all,
I have added IHtmlscriptElement ( a javascript function )
now i want to attach and event for the body tag
For example,
in the initial
.............
Dynamically i want to add as bellow
.............
How to add as above
Please some one help me
thanks in advance
|
|
|
|
|
do u want from .cs file
thanks ,
amit
|
|
|
|
|
Hi Friend,
thanks, yes i am doing in C# application only
if you guide me it will be much helpful for me.
thanks again
|
|
|
|
|
hi,
from .cs file u can use this I hope this will help u out
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "unSelectCheckbox();", true);
Thanks,
Amit Patel
|
|
|
|
|
Hi Friend,
Thank you,
I am using web browser control, in windows application,
so i get all the HtmlElement like body,form,div etc...
from there i want to attache this.
have a look at my code
mshtml.IHTMLElementCollection ecol = document.all;
if (ecol != null)
{
foreach (IHTMLElement elmnt in ecol)
{
string str = elmnt.outerText;
int k = 0;
if (elmnt.ToString() == "mshtml.HTMLHeadElementClass")
{
mshtml.IHTMLHeadElement head = (mshtml.IHTMLHeadElement)elmnt;
mshtml.IHTMLScriptElement element = (mshtml.IHTMLScriptElement)document.createElement("script");
element.text ="function EventRaise(){var m = document.activeElement.value;alert(document.activeElement.type);alert('The active element is '+m); }";
IHTMLDOMNode node = (IHTMLDOMNode)element;
document.appendChild(node);
}
else if (elmnt.ToString() == "mshtml.HTMLBodyClass")
{
}
}
}
i hope you may have some idea on that...
awaiting...
|
|
|
|
|
|
That image is very small, and i'm not sure i understood your question.
|
|
|
|
|
I may be wrong, but I don't think VS uses a rich text control. I would draw the text myself, especially for such a specific interface and I would expect MS to do the same.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
|
Yes, I understood that from your original post. You want collapsable regions similar to that implemented in VS.
You will have to code that yourself. There is nothing in the standard toolbox which will do it for you. Look at the Paint event, MeasureText, and DrawText for starters. Be aware, it won't be a trivial task...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Hi. plz show a sample for me .
|
|
|
|
|
|
ShaktisinhRathod wrote: I am Facing a problem in Word.Document.SaveAs(,)
It Shows Error "No overload for method 'SaveAs' takes '11' arguments"
when I run application on OTHER MACHINE which also using Office2003.
Same Applicaiton works On My machine with 16 arguments
Have you checked you are supplying 16 arguments? Beacuse the error says 11, and the compiler can normally count pretty well...
BTW: when I have to supply lots of arguments to a method, I tend to put them each on a separate line - it make identifying which is which a lot easier, and you can also comment them:
aDoc.SaveAs(ref destFile,
ref missing1,
ref missing1,
ref missing1,
ref missing1,
ref missing1,
ref missing1,
ref missing1,
ref missing1,
ref missing1,
ref missing1,
ref missing1,
ref missing1,
ref missing1,
ref missing1,
ref missing1);
missing1);
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
|
Check your references.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
|
Ah! So you created an application on one pc, and moved the .EXE file to another. When you run the application on the second PC, you get a run time exception "System.MissingMethodException: Method not found" or similar? Is this the correct sequence of events?
Have you installed Word on the second PC, and is it the same version?
Did you copy the EXE with a proper setup, or what?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
is there a way to do this in c#, i knew a way in c++, but all my searches have come to nothing, basically i am string the type of the class i am using in an xml file and trying to setup the exact type of class from the information stored in the xml file.
There has to be a way to do this as the xmlserialiser is able to do it/
|
|
|
|
|
|
Well, if I understood correctly what you need, the xml serializer is able to create a class from an xml document, but you need to know the class type.
If you have the class type name in a string, you can use Type.GetType to get the corresponding type object.
|
|
|
|
|
yeah i know that i am makin my own custom class serialiser, and am already referencing the GetType method from the class, what i weant to do is when i read the xml file and get the class type is to initialise the class from the class type (confusing i know)
|
|
|
|
|
The easiest way should to load the file using XmlDocument and get the type value from the corresponding node.
Then load the type and use it to initialize the serializer.
|
|
|
|