|
I may have figured out a solution, although it's a little sloppy. I'll post the code once I get it tested, but here's the idea:
- Create a custom control. Let's call this control "StyleChangedControl".
- StyleChangedControl will expose a custom event, StyleChanged.
- When a StyleChangedControl constructor is called, it will subscribe itself to the static event, StyleChangedControl.ApplicationStyleChanged. We'll call this new StyleChangedControl "NewStyleChangedControl".
- When I change the application style, I will call StyleChangedControl.NotifyOfStyleChange() (a static method).
- NotifyOfStyleChange() will fire the StyleChangedControl.ApplicationStyleChanged event (each NewStyleChangedControl will receive notification of that event).
- Once NewStyleChangedControl gets notification of the ApplicationStyleChanged event, it will itself raise its own StyleChanged event.
- In the resource dictionary that declares the style that contains the button, there will be an instance of StyleChangedControl.
- The button will have an event trigger that is subscribed to that NewStyleChangedControl's StyleChanged event.
- When that StyleChanged event gets fired, the event trigger will recognize it, and will then initiate an animation. This will accomplish the goal of firing an animation when the application style changes.
Effectively, I create a custom control that has a custom event that gets fired by the custom control class. There is a static method on that custom control class that allows another class to force the event to fire. Every single instance of the custom control will then receive that event. That event will be recieved by the event trigger in the style and will initiate the animation.
Anyway, that's all very confusing and it seems there must be an easier way. I'm not even sure it will work. I'll get back to you when I have some code to present. In the meantime, feel free to poke holes in the above process
Visual Studio is an excellent GUIIDE.
|
|
|
|
|
Seems overly complex. Give this a try.
In the OnStyleChnaged method you can start and stop your storyboards as needed.
Public Class MyButton
Inherits Button
Protected Overrides Sub OnStyleChanged(ByVal oldStyle As System.Windows.Style, ByVal newStyle As System.Windows.Style)
MyBase.OnStyleChanged(oldStyle, newStyle)
End Sub
End Class
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Hmm, I'm not sure that will work, as you don't have access to the animation from the MyButton.OnStyleChanged method. Also, I'm not quite sure I like the idea of inheriting from every control that I want to be able to animate on a style switch. However, I got my technique coded and it ain't pretty, but it works. Here is the code in all its horrific glory:
The resource dictionary in "AnimatedStyleDictionary.xaml":
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1">
<Style TargetType="Button">
<Setter Property="Button.Template">
<Setter.Value>
<ControlTemplate>
<Grid>
<local:StyleChangedControl x:Name="MyStyleChangeCon" />
<Rectangle>
<Rectangle.Fill>
<SolidColorBrush x:Name="rectFill" Color="Yellow" />
</Rectangle.Fill>
</Rectangle>
<ContentPresenter Content="{TemplateBinding Button.Content}" />
</Grid>
<ControlTemplate.Triggers>
<EventTrigger SourceName="MyStyleChangeCon" RoutedEvent="local:StyleChangedControl.StyleChange">
<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>
The main window XAML (just a button really):
<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">
<Button Click="Button_Click">Change Style</Button>
</Window>
The C# code behind the main window:
public partial class Window1 : Window
{
public Window1() {InitializeComponent();}
private void Button_Click(object sender, RoutedEventArgs e)
{
Application.Current.Resources.MergedDictionaries.Add(
(ResourceDictionary)Application.LoadComponent(
new Uri(@"AnimatedStyleDictionary.xaml", UriKind.Relative)));
Thread t = new Thread(new ThreadStart(delegate()
{
this.Dispatcher.Invoke(new ThreadStart(delegate()
{
StyleChangedControl.NotifyOfApplicationStyleChange();
}));
}));
t.Start();
}
}
The magical control that sends notifications of application style updates:
public class StyleChangedControl : Control
{
private static event ThreadStart ApplicationStyleChange;
public event RoutedEventHandler StyleChange
{
add
{
AddHandler(StyleChangeEvent, value);
}
remove
{
RemoveHandler(StyleChangeEvent, value);
}
}
public static RoutedEvent StyleChangeEvent =
EventManager.RegisterRoutedEvent("StyleChange",
RoutingStrategy.Direct, typeof(RoutedEventHandler),
typeof(StyleChangedControl));
public static void NotifyOfApplicationStyleChange()
{
if (ApplicationStyleChange != null)
{
ApplicationStyleChange();
}
}
public StyleChangedControl()
{
this.Visibility = Visibility.Collapsed;
ApplicationStyleChange += this.OnStyleChange;
}
private void OnStyleChange()
{
RoutedEventArgs e = new RoutedEventArgs(StyleChangeEvent);
RaiseEvent(e);
}
}
Like I said, it ain't pretty, but it works. Since I figured out my own solution, I'm going to mark this as solved. Thanks for all your ideas, Karl!
Visual Studio is an excellent GUIIDE.
|
|
|
|
|
While setting up a service reference for my silverlight app I keep getting the warning:
Web services at 'webserver' might not be accessible due to cross-domain restrictions:
For more details please contact the web server administrator or press F1 after selecting this warning
I've setup both a clientaccesspolicy.xml and crossdomain.xml in the web sites root directory. As far as I can tell they are configured correctly. But for some reason my Silverlight app seems to be either not seeing them or ignoring them.
If I browse to the file off my web root they are visible http://[URL]/crossdomain.xml etc.
Are there any secret ninja setting for getting this to work correctly? Web site permissions or script access settings?
clientaccesspolicy.xml
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="*">
<domain uri="http://*" />
<domain uri="https://*" />
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
crossdomain.xml
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>
|
|
|
|
|
Apparently visual studio was the name of my pain. When I setup my Service Reference, Visual Studio changed that URL it was actually supposed to be pointing to in my ServiceReferences.ClientConfig file.
So instead of pointing to <endpoint address="http://[IP Address]/SilverlightExample/CommunicationService.svc" that it was supposed to.
Visual Studio tried to point to: <endpoint address="http://[Machine Name].local/SilverlightExample/CommunicationService.svc"
Why on Earth it decided to re-write the URL I gave it for the service I have no idea.
|
|
|
|
|
Hello,
I'm an experienced programmer and I need to write a program capable of displaying a music sheet on screen.
My problem resides on the technology used for display. I first thought of OpenGL as I have experience with it and the TAOFramework that makes the use of OpenGL possible on .NET.
Then, well I have extensive knowledge of windows forms and all but I'm not really up to date on the latest versions of the framework so I think it could be done with WPF Microsoft marketted as wonderful.
So; my question for those still reading: could I write a fast, customm controller capable of displaying music sheet using WPF and if so could someone point me to some good starter page?
Thank you!
|
|
|
|
|
If it needs to be fast, I wouldn't use .Net at all...
"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
|
|
|
|
|
by "fast" i mean that I don't want it to lag when a user uses the scrollbar because it has to redraw. Anyway .NET will give me a much shorter development cycle.
|
|
|
|
|
There are lots of superb examples of just about every aspect of WPF here on the Code Project. Search, Read, Wonder and Enjoy.
|
|
|
|
|
I am designing an UI Application with WPF (XAML and C#). This application interacts with Database(sqlserver 2008) too. This app is a tool for the project.
I have to implement this with CAB architecture and Model-View-Presenter(MVP).
If I have functionalites like 1. Uploading data to database 2. Downloading data from database. then,
My questions are : 1. What will Model, View and Presenter roles in these applications.
How the interfaces between these modules happen?
Is it I have to Create IModel (interface) b/w presenter and Model, IView (interface) b/w presenter and view?
So, my codebehind will have only events calls (like btn_click) ??
Which module handles Database access?
I know I asked lot of questions, but I have made the UI ready for the rest of the work flow .
I am sorry if many questions are put in one place. I will be so glad, if I can get answers for all the things.
Kindly help me.
Thank you,
Ramm
|
|
|
|
|
|
Hi,
In a WPF Application using XAML,
I have 2 images, which needs to be oriental of horizantal. One is of width 784 * 66 and other is 1 * 66.
while, design time, since my window is auto it shows properly, but during runtime, the window is of 1280 width... so, the image 1 * 66 should stretch and cover the rest (1280 - (784 + 1))
|____________________________|_|
should become
|____________________________|_______________________|
which means , my firstimage should have the same width (784) and the second image should stretch to cover the rest even though its only one pixel.
<Grid HorizontalAlignment="Left" Height="66" Name="grdTopImages">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" MinWidth="1" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="66" />
</Grid.RowDefinitions>
<Image Name="imgClientPhoto" Grid.Column="0" Grid.Row="0" Source="/Honeywell.eHTMP;component/Resources/_left.gif"></Image>
<Image Name="imgExtraImg" Grid.Column="1" Grid.Row="0" Stretch="Fill" Source="/Honeywell.eHTMP;component/Resources/_right.gif"></Image>
</Grid>
Please help me
Thanks
Ramm
|
|
|
|
|
Hi Guys,
I could solve it,
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" MinWidth="1" />
should be the other way width property
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" MinWidth="1" />
Thanks a lot
Ramm
|
|
|
|
|
Hello,
I have a Silverlight 3 application where I use a tab control and I want to implement the navigational framework into it. The tabs on my page are created dynamically by the user, saying this
TabItem ti = new TabItem();
Frame frame = new Frame();
ti.Content = frame;
MyTabs.Items.Add(ti);
When the user clicks a link, I want content to load into whichever tab is currently selected, so I say this
HyperlinkButton btn = sender as HyperlinkButton;
string url = btn.Tag.ToString();
Frame frame = MyTabs.SelectedContent as Frame;
frame.Navigate(new Uri(url, UriKind.Relative));
The current tab loads the page into its frame correctly. However, as I click through the other tabs, they also have loaded the page into their frames, so all open tabs have the exact same content. So for example, the user has 5 tabs open. They click a link, and the currently selected tab loads a Page into its Frame. If they go to one of the four other tabs, they see that those tabs also loaded the same Page. How can I make sure that only the selected tab gets its new Page and not the other tabs? Thanks to anyone who can help.
|
|
|
|
|
Have you tried using Prism V2 (CompositeWPF)? There is a TabRegaion Adapter that you can use.
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
Microsoft MVP (Silverlight), WPF/Silverlight Insiders
|
|
|
|
|
Hi,
I am creating a Windows application (WPF) and C#. In my view, I have to add few layouts like browsing a folder, displaying the files in the folder in a list view...etc
My requirement is :
The panels mentioned above should be collapsible panels, I guess, we dont have option of collapsible panel in wpf.
I have to create a custom control for this? If so, Please suggest me how to do this?
Thank You,
Ramm
|
|
|
|
|
You could always use an Expander.
<Expander Header="Folders" IsExpanded="false">
..
</Expander>
"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
|
|
|
|
|
Is there a way to have the expander bump other elements out of the way? for instance if your collapsed expander is next to a list view, can you move the listview over when you expand? probably not possible but thought id ask
|
|
|
|
|
Hi everybody.
Could we use UDP protocol in WCF ?
Thanks.
|
|
|
|
|
If only there existed some mechanism for searching for information on the internet based on keywords. Why, this invention could make somebody very rich indeed. Clickety[^]
"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
I'm using a wcf service to get the data from the database and bind it silverlight control. And below is the code sample that i've written.
Problem here is WCF service that i've created is on basichttpbinding. Silverlight supports only this binding I think. So I changed the end point in my WCF service from default (wsHTTPbining ) to basic. when i add the service reference to the silverlight application the following is the silverlight clientconfig I'm getting with the error that i got when i build the application.
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ITestWCF" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8731/TestWCFLib/basic" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ITestWCF" contract="testService.ITestWCF"
name="BasicHttpBinding_ITestWCF" />
</client>
</system.serviceModel>
</configuration>
Unhandled Error in Silverlight 2 Application An exception occurred during the operation, making the result invalid. Check InnerException for exception details. at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary() at MNetMetricSystem.testService.GetBugCountCompletedEventArgs.get_Result() at MNetMetricSystem.OrganizationBaseLine.obj_GetBugCountCompleted(Object sender, GetBugCountCompletedEventArgs e) at MNetMetricSystem.testService.TestWCFClient.OnGetBugCountCompleted(Object state)
public partial class OrganizationBaseLine : UserControl
2 {
3 ServiceReference1.MNetMetricsServiceClient Metrics = new MNetMetricSystem.ServiceReference1.MNetMetricsServiceClient();
4 public OrganizationBaseLine()
5 {
6 InitializeComponent();
7 Loaded += new RoutedEventHandler(OrganizationBaseLine_Loaded);
8 }
9
10 void OrganizationBaseLine_Loaded(object sender, RoutedEventArgs e)
11 {
12
13 Metrics.GetAllDepartmentsCompleted += new EventHandler(Metrics_GetAllDepartmentsCompleted);
14 Metrics.GetAllDepartmentsAsync();
15
16 }
17
18 void Metrics_GetAllDepartmentsCompleted(object sender, MNetMetricSystem.ServiceReference1.GetAllDepartmentsCompletedEventArgs e)
19 {
20 cmdDepartMent.ItemsSource = e.Result;
21 }
22
23 }
24
25 This is the Service class from Interface
26
27 public class MNetMetricsService : IMNetMetricsService
28 {
29
30 DLMetrics objMetrics = new DLMetrics();
31
32 List mlist = new List();
33
34 List IMNetMetricsService.GetAllDepartments()
35 {
36
37 DataTable dt = objMetrics.DLGetAllDepartments();
38
39 mlist.Add(new MYList() { MyTable=dt});
40
41 return mlist;// List That i've return at the Silverlight application
42 }
43 }
I didn't use any LINQ to SQL to retrieve data from the database. Without LINQ is it possible? If possible what is the solution? Pls give some links on this......
|
|
|
|
|
I'm missing something here....where is the problem?
Is this a WCF problem or a database access problem?
You showed WCF configuration....is that from the client side or the server side?
What does the other end's configuration look like?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks Mark for the reply.
Problem is while adding service reference to the silverlight application in ServiceReference.ClientConfig file it shows the end points properly. That means no problem with WCF Service. In the WCFTESTCLIENT also I tested, It works very well.
But when I bind the service method in the pageloading event to a silverlight combobox control, It is showing the following error.....
Unhandled Error in Silverlight 2 Application An exception occurred during the operation, making the result invalid. Check InnerException for exception details. at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary() at MNetMetricSystem.Metrics.GetAllDepartmentsCompletedEventArgs.get_Result() at MNetMetricSystem.OrganizationBaseLine.Met_GetAllDepartmentsCompleted(Object sender, GetAllDepartmentsCompletedEventArgs e) at MNetMetricSystem.Metrics.MNetMetricsServiceClient.OnGetAllDepartmentsCompleted(Object state)
|
|
|
|
|
I can only guess with the given information.
Looks like you need to debug your server so you can get more meaningful
exception info. WHERE the exception is occurring would be helpful too.
The exception message you posted mentions checking the inner exception...
what's there?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Are you using DataTable? (From the looks of it your WCF returns DataTable)
Silverlight does not support DataSet and DataTable, therefore your WCF has to return the result as an ICollection, e.g. List, ArrayList.
Edbert
Sydney, Australia
|
|
|
|