I am trying to build the Image button by setting
<Button.Content>
<Image Source="..."/>
</Button.Content>
Everything is Fine but i am not able to set the Visual States when button is clicked i wanted to something like Flash on top of button (Blue Purple Theme).
One more thing I need to create around 10 such button with different Images I think Custom Control works fine.
Any help is appretiated.
Thanks
Lavanya
You'll want to re-template your Button(s) and wrap that up into a Style.
http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-7-using-control-templates-to-customize-a-control-s-look-and-feel.aspx
Then use the VisualStateManager (easiest from within Blend 3) to change the visual properties on various states.
http://silverlight.net/learn/tutorials/stylestemplatesvsm-cs/
Related
I want a button that
Displays an image with NO border, NO background, NO text
If I tab into the imagebutton, THEN it shows the background and border
Also if I hover over it, it shows the background and border
I've searched and I've tried so many different things, but nothing it exactly what I want. I've tried setting various properties on the button to make the background and border transparent, but it still shows up. I've tried a style with a custom control template. I'd rather not have to completely reinvent all the triggers etc to get the button to render on mouse over. The biggest problem with custom control template is that then I loose all existing functionality and I'm basically building a new control from the ground up.
Here is another link that came closest to what I wanted but it doesn't properly work for me.
How do you completely remove the button border in wpf? - BUT.... for some reason the hover effect gets stuck. One I mouse over the image and the button border draws, it stays stuck on until I click somewhere else.
Actually, you will want to override the control template. You're not "losing" any functionality (aside from the UI triggers).
Original/Default Template -- This is a good starting point... copy/paste that into you're XAML (wherever you want to style this button... ie Button resources, UserControl/Window resources, App Resources?). From there make your adjustments.
Another easy way is to use Expression Blend. You can easily create a new template based on the existing template, and the styling/authoring tools it provides are much better than hand-coding XAML (unless you're good at doing that).
As far as displaying an image instead of text, just set the image as the content. A Button is a type of ContentControl which means that it can house any type of content (Object).
I was able to add an item using the Window Handler and such, but I also want to remove the already existing items (the window tool window inside of our main app, and we don't want all those options there). In the screenshot below it shows the one I added and the ones I want to remove (pretty much all of them). Let me know if there's a way to do this.
EDIT:
Or better yet, how to put my own context menu with XAML (if possible). But I don't want to lose the title bar or the aero effect.
Thanks!
I know this answer is slightly different than what you are asking, but it may help. You are wanting to modify the built-in menu from the window title bar... but what if you overlay that menu with your own using custom chrome (like how mozilla firefox/MS Office does it)?
To do this, download WPF Shell Integration Library from http://archive.msdn.microsoft.com/WPFShell and play around with it. The library also includes a few other cool features like jump lists.
more documentation on this technique is at http://blogs.msdn.com/b/wpfsdk/archive/2008/09/08/custom-window-chrome-in-wpf.aspx
You can create your own ContextMenus in WPF
<Grid>
<Grid.ContextMenu>
<ContextMenu>
<MenuItem Header="Dock" Command="{Binding ...}" />
</ContextMenu>
</Grid.ContextMenu>
</Grid>
Just be careful with the Bindings because WPF ContextMenus are not part of the same Visual Tree as the rest of your controls, so bindings do not work as expected. You will probably need a relative source binding to the PlacementTarget to get your command.
I have the following code inside a RibbonSplitButton (which rendered correctly on the 3.5 ribbon CTP verion). I tried to view it using the WPF Ribbon 4.0 library, but it's just not rendering the Icon. Any idea why?
<ribbon:RibbonMenuItem Header="Option 3 - icon">
<ribbon:RibbonMenuItem.Icon>
<Image Width="16" Height="16" Source="Images/wizard-icon16.png"></Image>
</ribbon:RibbonMenuItem.Icon>
</ribbon:RibbonMenuItem>
Don't use the Icon property, that is inherited from MenuItem, and isn't used by the Ribbon control. Use the ImageSource property instead.
I also see the same problem. I've try to put even simple text in the Icon property but it just does not show anything.
I've check the control template and there is just no binding to the Icon property in it. You can use ImageSource to put an image in the menu item icon's place.
I guess it simply bad control template.
Add a forward slash in front of Images and do a Rebuild Solution. This is assuming the Images directory is located at the root of your project.
Is the image's build action set to Content?
HTH
Try setting the image's build action to Resource
I made myself a TransparentButton style that makes the Button portion behave the way I want it to (mouseover, enabled, etc), but what I haven't been able to do is set the content correctly in the style. Currently, I manually set everything in <Button.Content> for every button, and clearly that stuff needs to go into the Style. I have set the ContentTemplate for the style to a StackPanel that just contains an Image and a Label. The problem is, I don't know how to specify in my <Button ...> markup the Label's text and the Image's Source. I figured that it had to do with TemplateBinding somehow, but I've been searching like crazy and can't seem to find the information.
So, in summary, I just want a consistent button style where the button content is just a StackPanel of an Image and a Label, and I want to be able to create it in my GUI with something simple like:
<Button Style={DynamicResource TransparentButton}"
Label="Click Me" Image="Images/MyImage.png" />
Any tips would be much appreciated! I hope I'm on the right track here...
In order to create custom properties like this, you'll need to make a CustomControl instead of just using a Button style.
This is fairly easy, though - just make a custom control that subclasses button, and adds your new properties (as dependency properties). This will make it stylable, but also provide you the ability to enforce that those properties are always available, with the syntax you're describing (other than changing <Button to <local:MyButton).
For details, see the Control Authoring Overview on MSDN.
I have a button that is programatically created, it's content is a stack panel with an image and a textblock. This all works great.
I want to make the button behind the image and text transparent, so that the image and text looks like it's sitting on the background, but still have all the properties of the button (i.e. someone clicks in the button region it still registers the button click event).
I have been playing with opacities, but every opacity I play with dealing with the button seems to set the whole button (image and text included) to that opacity value as well.
How can I make the button opaque while making the text and image content still visible?
Oh, this is silverlight 3. Thanks in advance.
You are going to have to template the button and remove the gradients, focus element, etc that you don't want to keep from the default style for a button. It sounds like you probably just want to keep the content presenter and get rid of the background and mouse over "glow" gradients. You will probably have to set the background of your StackPanel content to be transparent if you want the entire button area to intercept mouse events and not just the underlying image and text content.
Scott Gu has a good tutorial here on the basics of creating a control template.
If you are using Expression Blend it's very easy to right-click on the button and choose Edit Template -> Edit a Copy to copy the default style into a new style resource for the button where you can then manipulate the template right in Blend.
You can override the template property of the button to make an empty grid, like so:
<Button>
<Button.Template>
<ControlTemplate TargetType="Button">
<Grid />
</ControlTemplate>
</Button.Template>
</Button>
This could be set as a reusable style if needed.