I am new to WPF applications. I come from a VB6 Windows Forms background. I used to create user controls that I used in UI's to create graphic content controls like buttons with normal, down,and hover images. While I know the ultimate way to do this is create a separate project for my custom controls I am just working withing a single project to get things worked out first.
I have created a Controls folder where I have added several custom controls each inherting from a base control like Button, RadioButton, Slider, Checkbox etc. I can then add properties to each custom control for DefaultImage, DownImage, HoverImage and in the case of a Slider GripImage and GutterImage. The properties have a public set/get property so I can set the images for a specific control and then the control behavior can set the proper image.
There is an Images folder where I put all the images needed for the application.
I have created a Images.xaml ResourceDictionary that defines key names like ButtonDown to the specific image names so the image naming in the template is easier and I can swap out images easily.
A Generic.xaml gets created in the Themes folder where the basic Control Template goes. Not sure if this is best practice for storing each Control Template or not but it is what gets created by default.
My main area of difficulty is creating the template. I know what I want to do but can't get the syntax to work correctly.
In the case of the custom button I want to create triggers for IsPressed and IsMouseOver and set the controls Background ImageBrush to the proper image. When those triggers are false I want to set the background image to the DefaultImage
I'm not sure about the syntax for refering to the image property of the custom Control and how best to access it in the xamal.
I've looked at a lot of examples but none seem to do things the way I am organizing it. I don't want to hard code the images to the control. My ultimate goal is to be able to drag the custom control into a grid using the designer and set the Default, Down, and Hover image properties and then place the control how I want it in the designer. Then if I want to change the entire look of the app I can just swap out images in the Images folder and the GUI will change.
For starters, you should only use images when its actually an image. For other cases, you should draw the part using XAML primitives. In the example you mentioned, the slider thumb and gutter and tick marks, etc. should all be drawn in XAML primitives. You'll find out why down the road .
When you are inheriting from a system control, you should generally NOT write your own template from scratch, but rather dump out the Microsoft template and either inherit from it, or paste it into your assembly and modify it. Reason being is that while Microsoft pushes "lookless" controls (the XAML has no knowledge of the code and the code has no knowledge of the XAML), you'll find out they are not. Controls often rely on primitives being in certain layouts and having certain names.
Dumping out the Microsoft templates is also a GREAT way to teach you how real world controls are put together.
I typically use Expression Blend for dumping out templates.
NOTE: unless you are going to have a control that is themeless, you need to do a lot of tricks to have say an XP theme, an Aero theme, Green theme, Blue Theme,etc. so you respect the users settings. If you are just going to have one look & feel across all themes / OS'es, etc. then you don't need to worry about that as much.
Just follow the Microsoft template lead to be honest with you... they are doing it "the right way".
I should probably point out that the UI's that I build are VERY graphic in nature with borderless nonsizeable main windows with irregular shaped graphic backgrounds. All Buttons, radios, checkboxes, sliders and other basic controls are designed by a graphic designer and then sliced up for the GUI. These are NOT standard UI's. The GUI's are used for small utility setting setup (think tooltray app for setting up some small feature) or they are internal tools that are used by non computer people or used as a demo on a large screen or demo room with specific hardware to demonstrate a feature.
That said...how do I "Dump out" a control template?
Yeah, I get it. As I said in my original response, that is how you did it in Win32 / MFC / Winforms, etc. If you are going to do WPF, you should use the WPF mechanisms. Otherwise, why bother? Not trying to be a dick, just saying lol... If you are not going to do that... might as well stick with Winforms, as you won't get any of the WPF advantages.
You will be surprised what can be drawn with WPF primitives... there's a guy on here who is a REAL stud at that...
download a copy of Expression Blend (a Microsoft app) and you can drag a control on a form, right click and dump out the template. You'll get full compilable XAML, all the brushes, resources, etc.
You'll notice EVERYTHING... buttons, checkboxes, radio buttons, etc. are all drawn with XAML.
Honestly, if you are working with a photoshop graphic designer (traditional), you might as well skip WPF as you'll just be piecing together all the graphics Winform style anyways. You really need a designer that knows the WPF tools (Expression Blend, Sketch Flow, etc). Should not be too hard for a photoshop guy to learn Expression Blend (if he is interested) as it pretty much works the same way... drop primitives like lines, curves, gradients, etc. on the form and do stuff.
You ***WILL*** need to draw ***EVERYTHING*** using XAML primitives if you want to do the fancy WPF stuff... animations, fading, special fx, etc.
The tooltip pops up, but the ToolTipHeader and and ToolTipDetails are blank. The Output window says it can't find them on the view model. How do I make the binding look on the Node, not the view model?
Hello, I'm building WPF(MDI) application. I want my main window to have some constant header and footer(like in a browser) and the area between the header and the footer will change dynamically. I googled but didn't find any thing useful, can someone help on this one?
Object reference not set to an instance of an object.
at WPF.MDI.MdiContainer.MdiContainer_Loaded(Object sender, RoutedEventArgs e)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
I have a application that has a page that receives multiple packets from a TCP/IP server. Every time it receives it tries to run an event using Dispatcher.BeginInvoke which runs the event. The problem is that the event only runs on the first time Dispatcher.BeginInvoke. I believe that the reason for this is that because the thread is already running it can not be started again. Also, I have tried the Backgroundworker class and as soon as it hits my code I get an "Invalid cross thread access" error which makes me put the code back into the Silverlight Dispatcher.BeginInvoke and the origional problem occurs. How do I fix my problem?
Without seeing your code it is hard to say. I think the issue here is that you are using the Dispatcher.BeginInvoke which is actually saying, marshal any work onto the UI thread. what could be happening is that if you first action does not complete or blocks the UI then subsequent events may not bubble up to the UI thread which would not show anything.
You were right in trying another thread. Firstly do your work on another thread. At the point of updating the UI, put that bit in the Dispatcher call. So what you are saying is: Do my work on another thread. Once it is complete and I want to update my UI, marshal it onto the UI thread using the dispatcher.
Please remember that the actual code is at my office at work and I am at home. I have network security rules that don't allow me to bring code home. However, this is a Silverlight page control the Do Work Complete bw_RunWorkerCompleted is the Async event that is called once the bw_DoWork is finishes. Now, 'TimeLine timeline' is a codeplex control which is a sub-control on the main page control that displays a Silverlight timeline. How it works is that a wcf call is made which fills the timeline's List<Event> events collection that is a property of the TimeLine control. Now, when timeline.UpdateEvents is called the timeline control iterates the list and re-draws the timeline with each of the collection's event objects. The Backgroundworker class provides an Async run event and on event complete combination. I have to put the 'while (!autoEvent.WaitOne())', sorry I forgot the while in the while loop, to wait until the main thread signals so that the Dispatch.BeginInvoke(timeline.UpdateEvents) is blocked unitl the collection is updated by the wcf call or I get an exception. I know that my discription is a bit sketchy but this is all I can go on as far a specifics until in the morning. If you can help that would be great!
I have created a simple silverlight application in VS2010(Silverlight 5) for open exe file. I host the application on my iis 7 and it is working fine. when i host in online(server), the elevated permission is failed and not entered to automationfactory. kindly suggest for open exe in online.