|
Yes thanks i did get it though i did not like the correctional facilities here.
|
|
|
|
|
Error 2 Assembly 'lab1' was not found. Verify that you are not missing an assembly reference. Also, verify that your project and all referenced assemblies have been built. D:\wpf\lab1\lab1\Window1.xaml 4 18 lab1
I am using the following code in order to use my user control in my project but the error mentioned before occurs :
xmlns:local= "clr-namespace:lab1"
PS: my Project and also Solution Name is lab1 so i am referencing to my project
please tell me what should I do, thank you
|
|
|
|
|
cppwxwidgetsss wrote: xmlns:local= "clr-namespace:lab1"
This may be a stupid question, and if so, I apologise. The statement above states that any future references in this XAML to 'local' are taken to refer to items in the 'lab1' namespace of this project. Are you sure the namespace is the same in your .cs files?
|
|
|
|
|
I am trying to follow the example from MSDN for creating a popup dialog to present the user with some options to change.
Here is my code to call the Dialog:
private void EditActivity()
{
EditWindow Editor = new EditWindow();
Editor.Owner = this;
Editor.ShowDialog();
if (Editor.DialogResult.HasValue && Editor.DialogResult.Value)
{
anActivity.Status = (bool)Editor.CheckBox.IsChecked;
}
}
In the code for the 'OK' button on the dialog, I have this:
private void OKButton_Click(object sender, RoutedEventArgs e)
{
if (ValidateWindow())
{
this.DialogResult = true;
}
}
If I run this, the Editor.DialogResult always comes back false.
I have run it in the debugger a bunch. The event is being fired and if I check the DialogResult immediately after calling this.DialogResult = true; , it shows false.
Am I missing something?
modified on Sunday, August 23, 2009 11:46 PM
|
|
|
|
|
Can you show the definition for DialogResult? Off the top of my head, I'd guess that you have something like this:
private bool m_dialogResult;
public bool DialogResult
{
get
{
return this.m_dialogResult;
}
set
{
}
}
But that is really just a wild guess. Also, if you could post the link to the MSDN example you are attempting to follow, that would be of use as well. That way, I can, for example, determine if DialogResult is implemented by you or by some other class that you inherit from.
Also, it depends on where you are putting your breakpoint. Is this.DialogResult = true; actually getting called? Or, is ValidateWindow() returning false and, therefore, preventing DialogResult from ever getting set?
Visual Studio is an excellent GUIIDE.
|
|
|
|
|
ValidateWindow() is returning true and this.DialogResult = true; is definitely being called.
DialgResult is a Property of the Window class.
Dialog Box Sample is here
|
|
|
|
|
Can you create a very minimal version of the code to reproduce the problem, then post it here? Below is my example and it seems to be working fine.
First, I created a new WPF project. I modified the main window. Here is the main window XAML:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<Button Click="Button_Click">Open Dialog</Button>
</Grid>
</Window>
Here is the main window C# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication1
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
MyTestDialog dialog = new MyTestDialog();
bool? ret = dialog.ShowDialog();
}
}
}
I also created another window that acts as a dialog. Here is the XAML:
<Window x:Class="WpfApplication1.MyTestDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MyTestDialog" Height="300" Width="300">
<Grid>
<Button Click="Button_Click">Click!</Button>
</Grid>
</Window>
Here is the C# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace WpfApplication1
{
public partial class MyTestDialog : Window
{
public MyTestDialog()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
}
}
}
That works perfectly fine for me. Does your code differ somehow?
Visual Studio is an excellent GUIIDE.
|
|
|
|
|
Can you change your code to the following and see if you see the MessageBox?
private void Button_Click(object sender, RoutedEventArgs e)
{
MyTestDialog dialog = new MyTestDialog();
bool? ret = dialog.ShowDialog();
if (ret == true)
{
MessageBox.Show("DialogResult returned true!");
}
}
My dialog also works, but my DialogResult is never set to true.
I will try to create a sample as well in the meantime.
|
|
|
|
|
K, I just tried that. I worked fine for me.
Visual Studio is an excellent GUIIDE.
|
|
|
|
|
I have created a sample and have tried your method and they both work. I fail to see any difference in that than what is in my original app.
I guess I have some digging to do. I'll get to the bottom of it.
Thanks for your responses...
|
|
|
|
|
OK. I found it.
There was an event that was being fired from a previous stage in development that was never removed, and it was setting the DialogResult to false.
It was confusing to me because the DialogResult was showing false immediately after the call to DialogResult = true; .
I am still not used to WPF and setting event handlers in XAML(Delphi convert).
Sorry for all the trouble, but thatnks a lot for trying to help.
|
|
|
|
|
I'm glad you figured it out. Remember to add "[Solved]" to the subject line on your original post.
Visual Studio is an excellent GUIIDE.
|
|
|
|
|
Hi everyone I'm new at wpf and I got some easy question:How can I get select item value from listbox? I wrote this code:
label1.Content = listBox1.SelectedItem.ToString();
and I get:System.Cindows.Control.ListBoxItem:Test1;
how can I get just Test1.
Thanks in advance!!
SOLVED
modified on Sunday, August 23, 2009 10:58 AM
|
|
|
|
|
What type of object is in ListBox1?
modified 27-Feb-21 21:01pm.
|
|
|
|
|
|
Don't be a retard and delete your posts. It makes the forums messy. Tell us how you solved it, so others can benefit.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
ListBoxItem item=listbox1.selectedItem();
label1.content=item.ToString();
Solution of problem
modified on Sunday, August 23, 2009 11:00 AM
|
|
|
|
|
|
Greetings,
I'm trying to throw together a quick silverlight proof of concept, but I'm stuck on a slight issue.
Let's say I have a base class (we'll call it Mammal) and two derived classes (dog and cat, respectively). I have an ObservableList<Mammal> that holds a whole bunch of cats and dogs.
Now, I have a listbox defined like so:
<ListBox x:name="lstMammals">
...
</ListBox>
A little ways further down, I have a ContentControl (I'm not sure if this is the right control to use here) that contains a StackPanel with two user controls in it. One of the user controls handles dogs and the other cats. How do I do the binding in XAML in such a way that when I select an item in the listbox that the appropriate user control pops up for editing it?
Or am I looking at the problem wrong?
Thanks,
Will
|
|
|
|
|
It sounds like you want a master/detail scenario...
Unfortunately, Silverlight doesn't support the rich, flexible data template
bindings to do this like WPF has, so you'll need a little code.
You can handle the listbox's selectionchanged event, and in your
handler show a detail control appropriate for the type of the selected item.
A search on "Silverlight master detail" yields several examples, like this
one: Using User Controls to Implement Master/Detail Scenarios[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
This is one for you WPF gurus. Basically, I want a button to pulsate continuously (i.e., fade from one color to another and back, then repeat forever). I've got that working, but it does not work under another condition. I also want to be able to change styles at runtime. I have the runtime style changing working and I have the pulsating button working, but not both at the same time. The problem seems to be that I'm using Button.Loaded as the event trigger that begins the storyboard. However, if I swap the style after the button has already loaded, that storyboard never starts, so the animation doesn't execute. I was thinking there was perhaps another event I could use (such as an "on style switch" event), but I'm really at a loss. Here is some simple code to help you understand the problem:
First, I have a resource dictionary stored in "AnimatedStyleDictionary.xaml". This contains the style for the pulsating button, as shown below:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="Button">
<Setter Property="Button.Template">
<Setter.Value>
<ControlTemplate>
<Grid>
<Rectangle>
<Rectangle.Fill>
<SolidColorBrush x:Name="rectFill" Color="Yellow" />
</Rectangle.Fill>
</Rectangle>
<ContentPresenter Content="{TemplateBinding Button.Content}" />
</Grid>
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="Button.Loaded">
<BeginStoryboard>
<Storyboard>
<ColorAnimation
Storyboard.TargetName="rectFill"
Storyboard.TargetProperty="Color"
To="Blue"
AutoReverse="True"
RepeatBehavior="Forever"
Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
Next, I have a Window with a button on it.
<Window x:Class="CodeProjectSample_RuntimeSwapAnimatedStyle.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Button Click="Button_Click">Hello</Button>
</Window>
When that button gets clicked, the application style gets switched (I know this is a poor technique, but I wanted to trim the code to a minimum for this sample):
private void Button_Click(object sender, RoutedEventArgs e)
{
Application.Current.Resources.MergedDictionaries.Add((ResourceDictionary)Application.LoadComponent(new Uri(@"AnimatedStyleDictionary.xaml", UriKind.Relative)));
}
The above code is where the failure occurs. The style gets applied (I can confirm because the button turns yellow), but the animation does not fire. Also, I have confirmed that the animation does work. If I modify the code to load the style in the Window constructor rather than the button, the animation works fine. However, that is not a working solution, as I want the user to be able to change between styles at runtime. Here is the code that causes the animation to work:
public Window1()
{
Application.Current.Resources.MergedDictionaries.Add((ResourceDictionary)Application.LoadComponent(new Uri(@"AnimatedStyleDictionary.xaml", UriKind.Relative)));
InitializeComponent();
}
Any help you could provide would be greatly appreciated!
Learn as if you would live forever, live as if you would die tomorrow.
modified on Thursday, September 3, 2009 6:29 PM
|
|
|
|
|
Did you try exposing an custom event that gets raised when the style changes? Then your event can fire when you app needs it to.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Great idea, that should cut my programming effort down about 100x. However, that still means I need to have every Window/Page subscribe to that event. Do you know of any way to force an event to fire on every Window/Page of a WPF application? Or, is there some way for an EventTrigger to subscribe to an event that does not get routed through the control that it is attached to (e.g., a static event on a class)? I'd rather cut my effort down by 1000x than "just" 100x
Visual Studio is an excellent GUIIDE.
|
|
|
|
|
Why not have the style subscribe to the event? Instead of Loaded, subscribe to MyStyleChanged event?
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Can you post an example of how I might do that (some code, or perhaps an article)? At least through event triggers, I only know how to subscribe to events that actually get routed through the control (in this case, a button) the event trigger is being applied to. I'm not sure how I would go about subscribing to an event on a static class (such as MyApplication.StyleChanged).
Visual Studio is an excellent GUIIDE.
|
|
|
|