|
I've a dataGrid in my XAML file. I need to display two separate context-menus on right-click on Rows and Header. Having same context-menu on both is easy, but how to have different ones? Will someone please provide a bit of code?
|
|
|
|
|
I think, I've got the answer.
<!--ContextMenu Definition-->
<ContextMenu x:Key="cm_rowMenu">
<!--ContextMenu For Row-->
</ContextMenu>
<ContextMenu x:Key="cm_columnHeaderMenu">
<!--ContextMenu For Header-->
</ContextMenu>
<!--ContextMenu Definition Ends-->
<!--Default Header Style-->
<Style x:Key="DefaultColumnHeaderStyle" TargetType="{x:Type Custom:DataGridColumnHeader}">
<Setter Property="ContextMenu" Value="{StaticResource cm_columnHeaderMenu}" />
</Style>
<!--Default Row Style-->
<Style x:Key="DefaultRowStyle" TargetType="{x:Type Custom:DataGridRow}">
<Setter Property="ContextMenu" Value="{StaticResource cm_rowMenu}" />
</Style>
<!--Setting styles for DataGrid-->
<Custom:DataGrid
RowStyle="{StaticResource DefaultRowStyle}"
ColumnHeaderStyle="{StaticResource DefaultColumnHeaderStyle}"/>
|
|
|
|
|
Yup - that looks like it should do it.
"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
|
|
|
|
|
Hello, i am very new to WPF and so far i like it more than WinForms.
Currently i have a template for ListViewItems. And i want to change the selected style. When i select an item, i see blue background.
Can anyone tell me where shoud i look into?
|
|
|
|
|
In WPF, the selected item background colour is determined by System.HighlightBrush. This means that you can define a brush for the style and use SystemColors.HighlightBrushKey to set this. Here's a sample:
<Style TargetType='ListViewItem'>
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Red" />
</Style.Resources>
</Style>
"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
|
|
|
|
|
Wow, thank you. I didn't ever knew it was possible to override system colors
|
|
|
|
|
You are most welcome. Ain't WPF cool?
"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
|
|
|
|
|
Pete O'Hanlon wrote: Ain't WPF cool?
I am asking mysely: Why didn't i tried this before
Now i have a diffrent problem. I do not think it is alrigt to contiune new post, but here it is:
This is a stripped down event Template for a ListViewItem template
<DataTemplate x:Key="ListBoxItemPodjetjeTemplate">
<Grid Margin="2">
<Border Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" BorderThickness="0" Background="#8098D8D8" CornerRadius="4,4,4,4"/>
</Grid>
<DataTemplate.Triggers>
<Trigger Property="Control.IsMouseOver">
<Setter Property="Control.Background" Value="LightGreen"/>
</Trigger>
</DataTemplate.Triggers>
</DataTemplate>
I put Highlight color to transparent, now i want to change background of an item based on mouse over. Now the trigger is throwing me an exception with an inner text: {"'{DependencyProperty.UnsetValue}' is not a valid value for property 'IsMouseOver'."}.
Thank you in advance
|
|
|
|
|
What value are you applying? You haven't actually set one in the Trigger. Try changing it to
<Trigger Property="Control.IsMouseOver" Value="True" />
"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
|
|
|
|
|
Aw stupid me. Thank you for your reply
|
|
|
|
|
No problems - it's easy to miss something like this. As a hint, if you ever see a message about DependencyProperty.UnsetValue then it means the value the DP expects hasn't been set. This isn't the same as a null value because null might be a legitimate value for the DP.
"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
|
|
|
|
|
I'm trying to learn WPF doing some simple stuff before tackling a real project. The first thing I've tried to do is to mock up an Excel sheet used to review case files. It uses 40 some columns to collect reviewers' input. At least 5 columns use the same Excel data validation to limit the responses to:
Yes,
No, or
Unknown
So..in porting this to SQL Server I've put check constraints in that require one of those 3 entries.
In mocking up the data entry form in WPF I would like to use a combobox that IS BOUND to one of those SQL columns and offers the 3 permissible choices. It seems to me that the ideal approach would be to create a template combobox with the 3 choices, and then use and re-use the template for each of the constrained columns.
Maybe my searching skills are poor, but I can't seem to find any explanations or examples of doing something like this, even though it seems as though this sort of thing would be used often.
Where do I start?
|
|
|
|
|
Normally, I'd approach this by using MVVM to bind to the items using a user control which contains the combo box, and the VM would contain the values (along with the validation). It's fairly straightforward, so I'd suggest that you have a read up on MVVM (that's Model View ViewModel).
"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
|
|
|
|
|
Pete -
Thanks for the response. I have been reading up on MVVM, but my 'programming' background has mostly been Excel VBA and some basic/rudimentary WinForm apps. It's a big step to grasp the concepts behind MVVM.
|
|
|
|
|
It is - but once you get it, it makes tasks like this so much simpler.
"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
|
|
|
|
|
Hello,
I am trying to build a WPF application using blend 3. I need to display HTML contents in a portion of my application window. I tried to use 'web browser' control for the purpose, it renders the HTML as desired. But the problem is when I apply a simple animation (change width) for the 'Web browser' control, using story board, the animation doesn’t take effect. I tried to play the story board at design time, animation is played as desired.
Can you please tell me how can I create animation for ‘Web browser’ and if it is possible please specify a sample? Are there any alternatives? Thanks in advance.
Regards,
Hassan
|
|
|
|
|
What kind of animations are you trying to apply to the control?
Post some code here - someone might have a suggestion or two.
|
|
|
|
|
In following code I try to animate webbrowser control directly and also by adding it to a dockpanel. In both cases I have no success, take a look
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Class="MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480" mc:Ignorable="d">
<Window.Resources>
<Storyboard x:Key="Ani1">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="webB1" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
<SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="webB1" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[1].(SkewTransform.AngleX)">
<SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="-12"/>
<SplineDoubleKeyFrame KeyTime="00:00:01.7000000" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="ani2">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="dockPanel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[1].(SkewTransform.AngleX)">
<SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="19"/>
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded"/>
</Window.Triggers>
<Grid x:Name="LayoutRoot">
<Button x:Name="btn1" HorizontalAlignment="Left" Margin="17,113,0,0" VerticalAlignment="Top" Width="56" Height="27" Content="Load" Click="btn1_Click"/>
<Button x:Name="btn2" HorizontalAlignment="Left" Margin="17,144,0,0" VerticalAlignment="Top" Width="56" Height="26" Content="Start" Click="btn2_Click"/>
<DockPanel x:Name="dockPanel" Margin="111,93,51,68" LastChildFill="False" RenderTransformOrigin="0.5,0.5" Background="Black">
<DockPanel.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</DockPanel.RenderTransform>
<WebBrowser x:Name="webB1" Margin="0,41,0,44" Width="462" Height="200" RenderTransformOrigin="0.5,0.5" d:LayoutOverrides="VerticalAlignment">
<WebBrowser.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</WebBrowser.RenderTransform>
</WebBrowser>
</DockPanel>
</Grid>
</Window>
VB code to call
imports System.Windows.Media.Animation
Class MainWindow
Private Sub btn1_Click(ByVal sender as Object, ByVal e as System.Windows.RoutedEventArgs)
dim uri1 as new Uri("http://www.codeproject.com")
webB1.Navigate(uri1)
End Sub
Private Sub btn2_Click(ByVal sender as Object, ByVal e as System.Windows.RoutedEventArgs)
'TODO: Add event handler implementation here.
Dim Lobj as Storyboard = directcast(me.Resources("ani2"), Storyboard)
Lobj.Begin
End Sub
End Class
Thanks
|
|
|
|
|
I want to create an image programatically, but I haven't been able to find a way to do it. I want to create a bitmap, render some text onto it, rotate it and then use the bitmap in a Image control.
EDIT===============
My current thought is to have the server side create the image and pas it back to me, but man, what a pain in the ass...
.45 ACP - because shooting twice is just silly ----- "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." - J. Jystad, 2001
|
|
|
|
|
If your image is an icon or a shape, you could actually use a path object. In thiw way, you dont need to actually use a bitmap or a jpeg.
These paths can be creted using Expression blend.
|
|
|
|
|
It's not a path. I want to create a transparent rectangle, render text on it, and then rotate it. The reason for that is I need a better appearance than what Silverlight can produce if I programatically add rotated content.
.45 ACP - because shooting twice is just silly ----- "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." - J. Jystad, 2001
|
|
|
|
|
Do you have to do it in the client? If you can do it on the server, I'd just create a memory device context, and draw on that one.
|
|
|
|
|
Michel Godfroid wrote: Do you have to do it in the client?
That would be preferred, but it looks like it's impossible.
Michel Godfroid wrote: If you can do it on the server, I'd just create a memory device context, and draw on that one.
Yeah, I mentioned that in my edit. At this point, I have to decide whether I want to do it in our web service, or create an aspx page that does it in the code behind.
.45 ACP - because shooting twice is just silly ----- "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." - J. Jystad, 2001
|
|
|
|
|
|
See new message in this forum.
.45 ACP - because shooting twice is just silly ----- "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." - J. Jystad, 2001
|
|
|
|