|
You can bind the list box to the collection and set the display member path property to the property name wich is name in this case and you will have all names displayed in the list
|
|
|
|
|
Dear friends,
I have wpf application
i could double click on the exe and N number of instance, but i want only one application to run.
how to do that?
any idea? suggestion?
Thank You
Joe.I
|
|
|
|
|
|
You have to take over the creation of the main form yourself, rather than using the StartupUri. A common way to do this is, in the OnStartup, detect whether or not another instance of the application is running by using a system wide mutex. Here's an example that does a basic level of checking:
private Mutex _mutex;
private override OnStartup(StartupEventArgs e)
{
_mutex = new Mutex(false, @"Global\\MyApplicationIdentifier");
if (_mutex.WaitOne(0, false))
{
base.OnStartup(e);
}
else
{
Application.Current.Shutdown();
}
}
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Thanks Pete O'Hanlon,
It works fine.
Thank you
by
Joe
|
|
|
|
|
Joe - you're welcome. Glad to help.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
you have to implement the singleton pattern in this case
move the startupuri attribute form the app.xaml and make the constructor of the statup window as private
then define a static method within the form and instanciate that form within that static method
private LunchWindow()
{
InitializeComponent();
}
static public LunchWindow Singleton()
{
return new LunchWindow();
}
override the OnStartup method of the app.cs and call that static method within the scope of the on startup method
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
LunchWindow singleInstance = LunchWindow.Singleton();
singleInstance.Show();
}
}
|
|
|
|
|
BechBej wrote: you have to implement the singleton pattern in this case
Errm, no you don't. Unless I am missing something really basic here, a singleton has no effect in this case because the singleton is per application domain.
The generally accepted way to do this is to use a Mutex to determine whether or not there is an instance of the application currently running.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I have a WPF app (that I didn't write - I just have the "pleasure" of fixing). The StartupUri in the app.xaml references mainwindow.xaml. But for some reason, I have a completely different page BasicView.xaml that is getting loaded first, prior to the MainWindow. Any idea what could be causing this?
Thanks
Phil
|
|
|
|
|
Check what's in your code behind App.xaml.cs.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Check the code behind at the two levels at the app.cs and at the Mainwindow.cs then tell me whether is there a code there
|
|
|
|
|
I am using C# Express 2010 on an XP box targeting .Net 4.0.
I have been following some examples from an article in MSDN Magazine[^]
At design time the ListBoxItems are visible, but at run time the ListBox is empty.
Here is the code, this is it, there's no code behind.
<StackPanel>
<StackPanel.Resources>
<XmlDataProvider x:Key="MoreColours" XPath="/colours">
<x:XData>
<colours>
<colour name="pink"/>
<colour name="white"/>
<colour name="black"/>
<colour name="cyan"/>
<colour name="gray"/>
<colour name="magenta"/>
</colours>
</x:XData>
</XmlDataProvider>
</StackPanel.Resources>
<TextBlock Width="248" Height="24" Margin="0, 5, 0, 0" Text="Colours:" TextWrapping="Wrap"/>
<ListBox x:Name="lboxColour" Width="248" Height="56" Margin="0,0,0,3" IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding Source={StaticResource MoreColours}, XPath=colour/@name}"/>
<TextBlock Width="248" Height="24" Margin="0,5,0,0" Text="You selected colour:"/>
<TextBlock Width="248" Height="24" Text="{Binding ElementName=lboxColour, Path=SelectedItem.Content, Mode=OneWay}"
Background="{Binding ElementName=lboxColour, Path=SelectedItem.Content, Mode=OneWay}"/>
</StackPanel>
The results are the same if I extract the XML to an external File, as here
<StackPanel>
<StackPanel.Resources>
<XmlDataProvider x:Key="Colours" Source="Colours.xml" XPath="/colours" />
</StackPanel.Resources>
<TextBlock Width="248" Height="24" Margin="0, 5, 0, 0" Text="Colours:" TextWrapping="Wrap"/>
<ListBox x:Name="lboxColour" Width="248" Height="56" Margin="0,0,0,3" IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding Source={StaticResource Colours}, XPath=colour/@name}"/>
<TextBlock Width="248" Height="24" Margin="0,5,0,0" Text="You selected colour:"/>
<TextBlock Width="248" Height="24" Text="{Binding ElementName=lboxColour, Path=SelectedItem.Content, Mode=OneWay}"
Background="{Binding ElementName=lboxColour, Path=SelectedItem.Content, Mode=OneWay}"/>
</StackPanel>
Does anyone have any idea why this might be. I am pretty sure that I have the code as in the article and I have asked a few days ago at the address given in the article, but have had no reply.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas? - Because 31 Oct = 25 Dec.
Business Myths of the Geek #4 'What you think matters.'
modified on Wednesday, June 30, 2010 6:51 PM
|
|
|
|
|
I'm not sure why your XML data island x:XData isn't working, but the second version has to be able to find the XML file in the same directory as the executable. Either set the properties on it to copy to the output directory, or give it the full path, i.e
.<StackPanel.Resources>
<XmlDataProvider x:Key="MoreColours" XPath="/MyColours" Source="C:\Mef\WpfXmlSample\WpfXmlSample\Colours.xml" />
</StackPanel.Resources>
[Edit]Deliver a slap sideways to my head. The reason your XData isn't being picked up is because it's trying to resolve against a namespace (i.e. you need to supply a namespace to map against the XPath). To get round this, add xmlns="" to the x:XData declaration (i.e. <x:XData xmlns=""> ).
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Thanks Pete. The empty namespace tip worked for my first example.
As far as the second (XML File) example the file is set to 'copy if newer' and it is definitely in the same directory as the exe. Before I posted I had already tried with it set to Build action of 'None' and 'Resource', neither of which worked.
If you, or anyone else, have any other ideas, I'd be glad to hear them.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas? - Because 31 Oct = 25 Dec.
Business Myths of the Geek #4 'What you think matters.'
|
|
|
|
|
I ran your sample with the following code and it works with this:
<Window x:Class="WpfXmlSample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<StackPanel.Resources>
<XmlDataProvider x:Key="MoreColours" XPath="/MyColours" Source="Colours.xml" />
</StackPanel.Resources>
<TextBlock Width="248" Height="24" Margin="0, 5, 0, 0" Text="Colours:" TextWrapping="Wrap"/>
<ListBox x:Name="lboxMyColour" Width="248" Height="80" Margin="0,0,0,3"
ItemsSource="{Binding Source={StaticResource MoreColours}, XPath=MyColour}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Mode=OneTime, XPath=@name}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</Window>
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Thanks for your help Pete!
Between that and a little experimentation I have managed to get it working.
Just in case you are interested, here's the code:
<Window x:Class="Binding_to_XML_File.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<StackPanel.Resources>
<XmlDataProvider x:Key="Colours" XPath="/colours" Source="Colours.xml" />
<XmlDataProvider x:Key="MoreColours" XPath="/colours">
<x:XData>
<colours xmlns="">
<colour name="pink" primary="true"/>
<colour name="white" primary="false"/>
<colour name="black" primary="true"/>
<colour name="cyan" primary="false"/>
<colour name="gray" primary="true"/>
<colour name="magenta" primary="false"/>
</colours>
</x:XData>
</XmlDataProvider>
</StackPanel.Resources>
<TextBlock Width="248" Height="24" Margin="0, 5, 0, 0" Text="Colours:" TextWrapping="Wrap"/>
<ListBox x:Name="lboxColour" Width="248" Height="56" Margin="0,0,0,3" IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding Source={StaticResource Colours}, XPath=colour/@name}">
</ListBox>
<TextBlock Width="248" Height="24" Margin="0,5,0,0" Text="You selected colour:"/>
<TextBlock Width="248" Height="24" Text="{Binding ElementName=lboxColour, Path=SelectedValue, Mode=OneWay}"
Background="{Binding ElementName=lboxColour, Path=SelectedValue, Mode=OneWay}"/>
</StackPanel>
</Window>
Now by changing ItemsSource="{Binding Source={StaticResource Colours}, XPath=colour/@name}" to ItemsSource="{Binding Source={StaticResource MoreColours}, XPath=colour/@name}" I can use the file or embedded XML
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas? - Because 31 Oct = 25 Dec.
Business Myths of the Geek #4 'What you think matters.'
|
|
|
|
|
Job done. Of course, you could also have consulted my article here[^] which demonstrates how to do something like this (without the XData side).
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hmmm. We seem to have attracted a univoter. Let me balance that out.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
It is being a busy little 'b' isn't it.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas? - Because 31 Oct = 25 Dec.
Business Myths of the Geek #4 'What you think matters.'
|
|
|
|
|
Chris has hunted down and delivered a beeyitch slapping.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi, All
i have VS2008 in my PC. Now i want to make a application in silverlight. I am unable to work with silverlight.
Acctually i have seen in the tutorials that we need to select silver light project from the new project window but i didn't find the same.
I have installed the silverlight by downloading it from silverlight.net but still but able to create the silverlight project.
I got a link for silverlight_Alpha for the same i install the same also, finally i got the silverlight template, but the problem remains the same when i tried to create a project i got a error "The project type is not supported by this installation"
So plz help me out. Plz tell me what to install for silverlight, from where i can download the same.
Thanks
Yogesh Agarwal
|
|
|
|
|
Since you are working with VS 2008, I'm assuming you must be installing Silverlight 3.
Just the SL runtimes are not enough for development.
You need the SDK + silverlight tooks (for VS 2008) which are included in the SL tools setup[^].
You will also need VS 2008 SP1.
|
|
|
|
|
you need to install Silverlight 3 SDK for vs 2008. not silverlight 4!!
|
|
|
|
|
souidi abderrahmen wrote: you need to install Silverlight 3 SDK for vs 2008. not silverlight 4!!
Correct. Since the OP is using VS2008, he can only use SL2 or SL3 and not SL4. This requires VS 2010.
|
|
|
|
|
that is right because i did the deploy on vs 2010, silverlight 4.
|
|
|
|