|
Couldn't agree more.
Regards
|
|
|
|
|
does anyone have a good sample?
I mean the kind of sample that is not done automaticaly by the wizard.
thanks!!
|
|
|
|
|
http://www.codeproject.com/KB/WPF/[^]
http://www.codeplex.com/[^]
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Hello coding Community,
i am currently developing with WPF on a more simple project but I got a problem and no googling could help me to find the answer.
I have several labels representing buttons on the GUI and I want them to work such as buttons work. So I used the MouseUp-Event but the debbuger only navigates to the event if I press the right Mousebutton not if I press the left Mousebutton. I tried that with nearly all MouseEvents, even with the MouseLeftButtonUp event, but it wont work. I don't know what to do next, so I ask here, because I don't want except probable future Users to click the right mouse button every time.
I'm glad about every help.
Greetings
MyPiano
|
|
|
|
|
i don't know why you're not getting the mouse button up event, but...
If you want the functionality of a button with the look of a label,
why not create a Button template instead of writing button functionality
yourself? I mean....that's one place WPF shines...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hmm... Thank you for this idea. It would be indeed a possibility. But then I have to redesign most of the program... And to tell the truth, I don't feel like programming a button. I know that I have to delete the border only but for me its most annoying that the MouseEvents on most controls don't work - by the way: .Net 3.5. On the Image control it's the same and if I want to use the Image as button it is again annoying espacially because I don't know how to set an Image on a button.
|
|
|
|
|
MyPiano wrote: for me its most annoying that the MouseEvents on most controls don't work
hmm....I don't know about anyone else, but if that were true, WPF would
be pretty useless to me.
MyPiano wrote: On the Image control it's the same
These events fire just fine for me:
<Image Name="theImage" Source="Images/Silverlight_Logo.jpg" Stretch="None" MouseLeftButtonDown="theImage_MouseLeftButtonDown" MouseLeftButtonUp="theImage_MouseLeftButtonUp" />
MyPiano wrote: I don't know how to set an Image on a button.
Here's an example of one way, using an image as the button's content:
<Button HorizontalAlignment="Center" VerticalAlignment="Center" >
<Image Source="Images/Silverlight_Logo.jpg" Stretch="None" />
</Button>
MyPiano wrote: It would be indeed a possibility. But then I have to redesign most of the program
Redesign? It would be a matter of simply adding a style and using buttons
with that style in place of your label that acts like a button:
<Style x:Key="LabelButtonStyle" TargetType="Button">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Label Content="{TemplateBinding Content}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
...
<Button Name="labelButton" Style="{StaticResource LabelButtonStyle}" Content="Label Button" Click="labelButton_Click" />
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thank you very much for these Codes. This will help me. I'm not programming very long with WPF, seems if I have much to learn.
Before I can mark this Thread as solved I have one question. Could the reason why the left mouse button doesn't work be that I don't ask whether the mouse-down event war fired? Stupid question because I think I know the answer, but I just want to ask because the (Left)MouseDown-Events work without problems...
Best regards
MyPiano
edit: I just got another Problem: I don't know where I have to put the <Style x:Key=""....
in the xaml editor.
modified on Friday, August 7, 2009 5:18 PM
|
|
|
|
|
MyPiano wrote: Could the reason why the left mouse button doesn't work be that I don't ask whether the mouse-down event war fired?
I haven't seen any of your code so I could only guess. How do
you know it's not working? To test the code I posted, I just
put a breakpoint in the event handler method and ran the app in the
debugger.
MyPiano wrote: I don't know where I have to put the <Style x:Key=""...
That is explained here: Resources Overview[^]
Here's a more complete example:
<Window x:Class="WPFTester.MyWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFTester"
Title="MyWindow" WindowStartupLocation="CenterScreen"
Width="300" Height="300">
<Window.Resources>
<Style x:Key="LabelButtonStyle" TargetType="Button">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<Label Content="{TemplateBinding Content}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<StackPanel>
<Button Name="labelButton" Style="{StaticResource LabelButtonStyle}" Content="Label Button" Click="labelButton_Click" />
<Button HorizontalAlignment="Center" VerticalAlignment="Center" >
<Image Source="Images/Silverlight_Logo.jpg" Stretch="None" />
</Button>
<Image Name="theImage" Source="Images/Silverlight_Logo.jpg" Stretch="None" MouseLeftButtonDown="theImage_MouseLeftButtonDown" MouseLeftButtonUp="theImage_MouseLeftButtonUp" />
</StackPanel>
</Grid>
</Window>
using System;
using System.Windows;
using System.Windows.Controls;
namespace WPFTester
{
public partial class MyWindow : Window
{
public MyWindow()
{
InitializeComponent();
}
private void labelButton_Click(object sender, RoutedEventArgs e)
{
} <code>
private void theImage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
} <code>
private void theImage_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
} <code>
}
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for this detailed answer. The LabelButton works perfect, the ImageButton works too.
The image fires only the MouseLeftButtonDown event but not the Up-Event.
|
|
|
|
|
MyPiano wrote: The image fires only the MouseLeftButtonDown event but not the Up-Event.
Remove the breakpoint from the down event.
If it still doesn't work, you have other unknown issue(s)
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hey Mark,
i found the problem now. After a second very intensive research on google, I found this MDSN article:
UIElement.MouseLeftButtonDown Event
The problem was that the control didn't captured the MouseButton after the MouseDownEvent because the Mouse probably moved over other object or st. similar. So I captured the mouse on the control:
private void label4_MouseDown(object sender, MouseButtonEventArgs e)
{
label4.CaptureMouse();
}
private void label4_MouseUp(object sender, MouseButtonEventArgs e)
{
label4.ReleaseMouseCapture();
}
That's all. As someone who worked with normal windows forms applications in the past a strange solution but okay.
Thanks for the tips and your patience.
Best regards
MyPiano
|
|
|
|
|
Hi,
I am evaluating Silverlight as a UI for a new application and I'm looking for some advice. I'm fairly new to Silverlight.
Background: I am working with a database that provides it's own ADO.NET native adapter. Using this native provider, I can define ADO.NET Commands ith SQL Statements and run ExecuteQuery methods against the database to retrieve datasets. This all works fine when building a traditional client/server thick client.
Now to Silverlight....
I am of the understanding that Silverlight (any version) will need to call a WCF web service (typically hosted by a ASP.NET Web application on a web server somewhere) right ?.
A proxy class built on the Silverlight side is what is used to drive the web service, and controls are bound to this class.
I have managed to build a simple Silverlight application that takes the input of two integers and displays the sum. This is done by calling an AddIntegers web method exposed by the web service, which returns the sum as a result. So far so good. However ...
How do I go about gettings rows of information, like, a resultset from my database and into SL ?
Within by web method (say, ContactNames()), I can execute ADO.NET type commands to interact with my remote database, but once I get that dataset, I do not know how to return it to silverlight for populating into a grid...
Any help would be greatly appreciated, articles, sample code, .. anything ...
Thanks
|
|
|
|
|
Typically you will want to exchange strongly typed classes. So, have your web method return List<Customers> (or whatever else you need), and then populate that data into a grid using data templates in Silveright.
A google search for silverlight data templates will get you what you need on that end.
modified on Friday, August 7, 2009 1:27 PM
|
|
|
|
|
pisanis wrote: I am of the understanding that Silverlight (any version) will need to call a WCF web service
You don't have to use WCF.
For example a plain old XML (POX) web service could be used. Silverlight
can bind directly to the returned XML or if necessary you could convert the
returned XML to an object or collection of objects using perhaps LINQ to XML.
*edit* Oops - drifted into WPF Land there
pisanis wrote: How do I go about gettings rows of information, like, a resultset from my database and into SL ?
pisanis wrote: once I get that dataset, I do not know how to return it to silverlight
There's a variety of ways to accomplish this.
If you choose to use WCF, you could return a collection of objects of a class that
represents a row of data. You would convert dataset rows to this collection of
objects, perhaps using LINQ to DataSet.
You may also want to look into .NET RIA Services, which is still in development and
will probably be officially part of .NET 4, but there is a preview version[^] available
which is now licensed to use live.
Mark Salsbery
Microsoft MVP - Visual C++
modified on Friday, August 7, 2009 1:30 PM
|
|
|
|
|
The most of your questions are already answered by our Codeproject Silverlight Experts.
I will just add one more point here.
If you really want to return the DataSet from Service then you may want to check-out the code written by one of our Silverlight community members. The link for that is here[^].
But returning the dataset from service is not a good idea but the most of .NET developers who are familiar with .NET 1.1 and 2.0 still prefer to use DataSet.
Another thing is that DataSet will not be supported in Silverlight.
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
Microsoft MVP (Silverlight), WPF/Silverlight Insiders
|
|
|
|
|
I recently started learning Silverlight. While doing a sample code I got stuck with how to load Silverlight UserControl dynamically from the same .xap file. Imagine a scenario where we have two UserControl; Login and Reports. User would need to login to see the report page. On click of the Login button the Reports UserControl should be loaded and Login UserControl should be unloaded.
I was able to achieve this functionality by using delegate. I will try to explain the bit I have done to achieve this.
Declare a base class which inherits from the UserControl class. The base class will exposes a delegate to handle the dynamic loading of the usercontrol.
BaseUserControl.cs
namespace MyFirstSLApp
{
public delegate void ControlChangeHandler(object control, int ctrlId);
public class BaseUserControl : UserControl
{
public ControlChangeHandler OnContentChange;
}
}
Create a Login UserControland inherit it from the BaseUserControl class. Here we will implement the code to notify the subscriber for the UserControl change.
Login.xaml
<control:BaseUserControl xmlns:dataInput="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input" x:Class="MyFirstSLApp.Login"
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlnsBig Grin="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:control="clr-namespace:MyFirstSLApp"
Width="400" Height="200" >
<Grid x:Name="LayoutRoot" Background="White" Width="400">
<Grid x:Name="LoginLayout" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="70"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20"></RowDefinition>
<RowDefinition Height="20"></RowDefinition>
<RowDefinition Height="20"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Text="User Id:" Grid.Column="0" Grid.Row="0" ></TextBlock>
<TextBox x:Name="txtUserId" Grid.Column="1" Grid.Row="0" ></TextBox>
<TextBlock Text="Password:" Grid.Column="0" Grid.Row="1"></TextBlock>
<PasswordBox x:Name="txtPassword" Grid.Column="1" Grid.Row="1"></PasswordBox>
<Button x:Name="btnLogin" Content="Login" Click="btnLogin_Click" Grid.Column="0" Grid.Row="2"></Button>
<!--<Button x:Name="btn" Content="Login" Grid.Column="3" Grid.Row="0"
Grid.ColumnSpan="2" Grid.RowSpan="2"></Button>-->
<TextBlock x:Name="txtError" Text="" Grid.Column="0" Grid.Row="4" Grid.ColumnSpan="4"></TextBlock>
</Grid>
<dataInput:ValidationSummary >
</dataInput:ValidationSummary>
</Grid>
</control:BaseUserControl>
Login.xaml.cs
private void btnLogin_Click(object sender, RoutedEventArgs e)
{
if (OnContentChange != null)
OnContentChange(this, 1);
}
Note: Since we have inherited the Login control from BaseUserControl control, I have used control:BaseUserControl tag instead of UserControl tag. To enable the compiler to recognise BaseUserControl tag, add following entries to AssemblyInfo.cs file
[assembly: XmlnsDefinition("http://schemas.microsoft.com/client/2007", "MyFirstSLApp")]
Create a UserControl which will acts as the container for loading the controls dynamically.
Page.xaml
<UserControl x:Class="MyFirstSLApp.Page"
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ctrl="clr-namespace:MyFirstSLApp"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
</Grid>
</UserControl>
Note:Here the <Grid> control will act as a container. We can dynamically add the UserControls to its UIElementCollection. This gives us a flexibility to add or remove a control at runtime.
Finally subscribe the delegate in APP class. Here we will manipluate the Children collection of the Page Control to dynamically display UserControls.
App.xaml.cs
private void Application_Startup(object sender, StartupEventArgs e)
{
Page page = new Page();
Login login = new Login();
ContentChange(login);
page.LayoutRoot.Children.Add(login);
this.RootVisual = page;
}
public void ContentChange(BaseUserControl control)
{
control.OnContentChange += new ControlChangeHandler(control_OnContentChange);
}
void control_OnContentChange(object control, int ctrlId)
{
Page page = null;
switch (ctrlId)
{
case 1:
page = (Page)this.RootVisual;
page.LayoutRoot.Children.Clear();
Reports report = new Reports();
page.LayoutRoot.Children.Add(report);
ContentChange(report);
break;
case 2:
page = (Page)this.RootVisual;
page.LayoutRoot.Children.Clear();
Login login = new Login();
page.LayoutRoot.Children.Add(login);
ContentChange(login);
break;
}
}
AR
modified on Friday, August 7, 2009 7:21 AM
|
|
|
|
|
Friends we are creating application in WPf. Now the problem that i am facing right now is that my Application have too many child window. i want that when any child window is showed it should be right aligned with other child window and main window plus when we drag main window the child should also align with it i use an event location change and then iterate through childwindows of the main window and then change the location but is there any other proper way????
WANTED wasim khan(Killed 50 Innocent Buggs, Distroyed 200 Exception, make 5 Project Hostage) any Compnay Hire him will pay 30,000. Best place where u can get him is Sorcim Technologies Murre Road RWP
|
|
|
|
|
Why don't you hook each child window to an event that indicates that the parent window is being moved (or has moved)?
With a short google search I found (and you could have too) this:
http://stackoverflow.com/questions/926758/window-statechanging-event-in-wpf/928798[^]
I don't know if it will help you, but I'm neither emotionally nor financially invested in your finding an answer to your question, so you'll have to take over from here.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I'm sorry about bothering you with such noob question!
I'd like to start programming a simple raster drawing program for WPF with layers, etc. (something like paint.net) as a learning project.
Do you have any ideas where should I start? I've tried to find similar projects to look at for ideas on google but I couldn't.
What components and base classes are suitable to try?
|
|
|
|
|
0) Start Visual Studio
1) Click File | New... | Project...
2) On the left side of the subsequent dialog box, click "Windows"
3) On the right side, click "WPF Application"
4) At the bottom of that dialog, enter an entertaining, yet applicable name for your new project.
5) Click the OK button.
6) Next.... ah hell, I'm bored - you can take it from here.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Nice advice. I've done it. And now if you tell me how to draw pixels on the screen you'll be my God!
|
|
|
|
|
I only help those who help themselves.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: I only help those who help themselves.
Yeah! "God helps those who help themselves" - I know that proverb!
What a senseless discussion! Not only you are not helping me but you are wasting my time by making me check your posts.
Thanks a lot!
P.S. You've missed your opportunity to make a good deed today and help yourself gather credits for the heaven and you've made an evil one. One day you'll have to answer for your sins!
|
|
|
|
|
Cristoff wrote: God helps those who help themselves
So, you're saying that John is God. Please don't - his ego will run rampant.
Cristoff wrote: P.S. You've missed your opportunity to make a good deed today and help yourself gather credits for the heaven and you've made an evil one. One day you'll have to answer for your sins!
Not a good way to get others to want to help you.
"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
|
|
|
|