|
You could probably dig into the ListView style and template to get what you want,
but I personally would use the DataGrid control from the WPF toolkit (assuming you're
using the Grid view on your ListView).
Using the DataGrid, getting your desired look and feel (single cell select, no resizing
columns, no header mouseover effect) would be as simple as something like this:
<wpftk:DataGrid x:Name="dataGrid1" AutoGenerateColumns="True" SelectionUnit="Cell" SelectionMode="Single"
CanUserResizeColumns="False" CanUserSortColumns="False"
ItemsSource="..." GridLinesVisibility="All" VerticalGridLinesBrush="Black" HeadersVisibility="Column"
AlternatingRowBackground="LightSteelBlue" Height="300" >
<wpftk:DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type wpftk:DataGridColumnHeader}" BasedOn="{StaticResource {x:Type wpftk:DataGridColumnHeader}}">
<Setter Property="Background" Value="SteelBlue" />
<Setter Property="Foreground" Value="White" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
</wpftk:DataGrid.ColumnHeaderStyle>
</wpftk:DataGrid>
*edit* Also, see Jaime Rodriguez's three part article on the DataGrid:
Dabbling Around the New WPF DataGrid[^]
It's a little "old" but covers the basics well
Mark Salsbery
Microsoft MVP - Visual C++
modified on Saturday, May 9, 2009 5:17 PM
|
|
|
|
|
Good Morning,
thanks a lot for you reply.
Actually I solved it with a TextBlock-Collection, sure this is not a clean way to develope, but it works.
The DataGrid will be interesting and I will get into it in the next days.
cu s00n
eXi
|
|
|
|
|
Hi all,
Is there a way to run wpfbrowser application in linux?
Thanks in advance....
Krishnraj
|
|
|
|
|
|
I have a button on a control, which itself is on a window. The window doesn't know about the button, but it needs to handle the event. The way I've been doing it up to now is to add x:FieldModifier="public" to the button, but that somehow feels wrong (even though it works).
Is this the most proper way to handle event in this situation, or is there a more WPF-appropriate way to do it?
"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
|
|
|
|
|
The standard .NET way to do this is for the user-control to have an event that exposes the internal event. If the button is called say "Save", then the user-control will have a Save event, and the Save event will be internally fired from the click handler for the button. The window now handles this exposed event on the user-control.
Making the user-control's button public is not a very good approach at all (like you said). That's a typical VB6-ish way of doing things.
|
|
|
|
|
What's the benefit of routed events then? If it's not automatic in some way, what's the point?
"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: What's the benefit of routed events then? If it's not automatic in some way, what's the point?
In this particular case routing this event (either via bubbling or tunneling) won't be very natural. That would apply in a different scenario - say you have a user-control with some child-textbox controls. Now say you want a double-click event on the user-control that will fire even when the textbox control's double click is fired (and not just when a blank area within the user-control is double clicked). In this scenario, the textbox's event handler should bubble it up to the parent. It sounds a little weird but that's the way things seem to be done in WPF.
|
|
|
|
|
I agree with Nish...I would keep knowledge of the button internally encapsulated
in the control class and only publicly expose any required functionality...regular
OOP stuff, which allows you to change the controls innards without changing the public
interface.
As far as routed events - routing is along the visual/logical trees - not really
applicable to what you're asking I don't think.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Well it is actually a bad design decision (good thing this isn't production code). I didn't want a full-on toolbar because of the decorations that are added to them by default (and I really didn't have time to figure out how to hide them). So, I created a user control that serves as the toolbar. Bad idea, because I now have the implementation crap to deal with in terms of being able to see the button from (a) the window that contains the control and b) tabs in the window that contains my faux-toolbar user control.
I was sitting around today getting pissed off at WPF, and re-implemented the faux-toolbar as a stackpanel/grid combination, this time, directly on the window instead of as a user control. This means I still have to make the buttons public, or manually implement an event forwarding mechanism, and as indicated, I know the technically most correct action to take, but the lazy redneck in me is satisfied with making the buttons public. I was just wondering if I was missing a concept of routed events, and apparently, I'm not. It's the same old sh*t with a shiny new name and an obscure reason for existing.
"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
|
|
|
|
|
Depends on what you are trying to do. If a button click should cause some change on the model rather than the UI, you should look into commands and leave the Window completely out of the picture. In that case, you set the Command property of the button rather than handling the click event.
If you want to bubble the click event on a higher level, you can just register an event listener on a higher level through XAML:
<SomeContainerControl Button.Click="MyEventHandler">
<SomeChildControl>
<!-- clicks bubble up the visual tree -->
<Button x:Name="myPrivateButton" />
</SomeChildControl>
</SomeContainerControl>
hth, Philipp
NetDrives - Open Source Network Share Management
|
|
|
|
|
If he has multiple buttons, he'd have to switch-case on the Text or Name properties. In this case, I believe handling a custom event on the user-control is a better approach than handling the bubbled event.
|
|
|
|
|
...which is where I would opt for different commands (or alternatively: command parameters). And he stated that the window does not know about the button (which indicates separation of concerns on the UI level). However, it's hard to tell without knowing the use case
Cheers,
Philipp
NetDrives - Open Source Network Share Management
|
|
|
|
|
John - to be honest, you need to look at using MVVM (definitely a version with the Mediator pattern as part of it). This architecture is designed to cope exactly with scenarios like this.
"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 have the following problem:
I want to know the width and height in pixels of a text string of a certain length.
I tried using TextBox.GetRectFromCharacterIndex() but this didn't work. I suspect the reason is that the textBox has not been drawn before I invoked this method. I just assigned the Text property a value. The resulting rectangle is {empty}.
Is there a way to obtain the pixel dimensions of a string without haven drawn or shown it. I certainly know that the result also depends on the text formating. Nevertheless, is there a way to obtain this information?
thanks in advance
Lars
#pragma error( disable : * )
|
|
|
|
|
You need to get the current display context, and then call the Graphics.MeasureString() method.
"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
|
|
|
|
|
thanks for your reply. I forgot to mention that I want to limit myself to the WPF API. Nevermind, your answer helped me figure out the WPF-way of doing it.
I am using now an instance of FormattedText und ask its Width and Height properties.
Interestingly there exists a method GetMaxLineWidths() in this class but it doesn't work as I expected. It always returns {null}.
Regards,
Lars
#pragma error( disable : * )
|
|
|
|
|
I'm looking at this problem again, and I still haven't been able to figure out why it's not working. I have a number of XAML files in a WPF UserControl library that contain various elements.
In Resources.XAML:
<ImageBrush x:Key="ImgBrushQuickLaunch" Stretch="Fill"
ImageSource="/MyResourcesLib;component/Images/GlassQuickLaunch64.png" />
In Styles.XAML:
<Style TargetType="{x:Type Button}" x:Key="StyleUDPButton">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Opacity" Value="0.40" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="StyleButtonQuickLaunch" TargetType="{x:Type Button}"
BasedOn="{StaticResource StyleUDPButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border CornerRadius="18" Background="{DynamicResource UDPQuickLaunch}">
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Finally, in the main application Window (in the main application), I'm doing this:
<Window x:Class="TestingPlatform.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">
<Grid>
<Button Name="button1" Style="{DynamicResource StyleButtonQuickLaunch}"
Margin="60,58,0,0" HorizontalAlignment="Left" VerticalAlignment="Top"
Height="37" Width="37"
BorderThickness="0" BorderBrush="Transparent" />
</Grid>
</Window>
My problem is that despite there being no errors or warnings, the button does not show up in either the designer, nor the running application. In fact, I can't get the button to show up at all unless the custom style isn't attached, even if I take off the BasedOn property.
"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 - this should fix it. In your App.xaml, you need to add these resource dictionaries to the global resources using:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources.xaml" />
<ResourceDictionary Source="Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
"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'd already done that.
"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
|
|
|
|
|
As I mentioned in your previous post on this, you don't have anything visible in your
button template, so you won't see anything.
For example, if I change your template to...
<Style x:Key="StyleButtonQuickLaunch" TargetType="{x:Type Button}"
BasedOn="{StaticResource StyleUDPButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border CornerRadius="18" <code>BorderBrush="DarkGreen" BorderThickness="2" Background="LightGreen"</code>>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
...then use the style on a button something like this...
<StackPanel>
<Button Name="button1" Style="{DynamicResource StyleButtonQuickLaunch}" Height="50" />
</StackPanel>
...then it works great.
That's why I asked you before if re-templating controls all the time is really what you want,
or do you just want to just modify certain properties of existing controls using style setters....
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Need a sample video Conferencing application using wpf
|
|
|
|
|
Jeena S wrote: Need a sample video Conferencing application using wpf
Try rentacoder then; or search google for one.
"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'll give you mine but it's pretty expensive
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Is there a way I can create forms dynamically(not load, but create), and get the XAML of the form as the output. Is there a tool that can do it? In which I could specify the location and type of control I want to put on the form?
Thanks
|
|
|
|