|
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
|
|
|
|
|
As XAML is just XML, you could write it out using the XML features of .NET and then compile it/load it using the XamlReader class.
"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 want to create datetime, time and duration control...
I have created the datecontrol by using datepicker available in Silverlight....
Do we have any existing controls available in Silverlight 2.0 so that I can make datetime, time and duration controls...?
Or have to extend some controls to get above controls?
Can anybody have some code / hyperlinks from where I can get the idea?
|
|
|
|
|
How to write a type-ahead (suggests) control in WPF.
thanks
Ganesh
|
|
|
|
|
|
I have ListBox in test.xaml:
<grid>
<listbox margin="12,28,0,0" name="ListBox1" horizontalalignment="Left" width="77" height="100" verticalalignment="Top">;
;
And in the test.xaml.cs file, I initialized the ListBox as
for (int i=1; i<=50; i++)
{
ListBox1.Items.Add("Item" + i);
}
Now I want to set a "HelpText" AutomationProperty to each of the ListItems. How do I do it?
I heard it could be done through Binding? Can some one provide me the required info?
Thanks.
|
|
|
|
|
[Reposting; Some problem in text display]
I have a test.xaml:
<Grid>
<ListBox Margin="12,28,0,0" Name="ListBox1" HorizontalAlignment="Left" Width="77" Height="100" VerticalAlignment="Top" />;
</Grid>;
And in the test.xaml.cs file, I initiatilize the ListBox
for (int i=1; i<=50; i++)
{
ListBox1.Items.Add("Item" + i);
}
Now I want to set a HelpText AutomationProperty to each of the ListItems. i.e. HelpText1 to Item1, HelpText2 to Item2 and likewise. How do I exactly do it?
Thanks
|
|
|
|
|
Hello..
I want some help from you guys in my wpf project.
I prepared my project using MVVM pattern.
I am using HeaderedContentControl and in content presenter of that i am using tab control.
MyControl.xaml
<Window.Resources>
<Style x:Key="HeaderStyle" TargetType="{x:Type HeaderedContentControl}">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<Border BorderBrush="LightGray" BorderThickness="1" CornerRadius="5" Margin="4" Padding="4" SnapsToDevicePixels="True">
<TextBlock FontSize="14" FontWeight="Bold" Foreground="White" HorizontalAlignment="Center" Text="{TemplateBinding Content}" />
</Border>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type HeaderedContentControl}">
<DockPanel>
<ContentPresenter
DockPanel.Dock="Top"
ContentSource="Header"
ContentTemplate="{TemplateBinding HeaderTemplate}"
/>
<ContentPresenter
ContentSource="Content"
ContentTemplate="{TemplateBinding ContentTemplate}"
/>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<DataTemplate x:Key="MyWorkingTemplate">
<TabControl
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding}"
ItemTemplate="{StaticResource ClosableTabItemTemplate}"
Margin="4"
/>
</DataTemplate>
</Window.Resources>
<HeaderedContentControl
Content="{Binding Path=Workspaces}"
ContentTemplate="{StaticResource MyWorkingTemplate}"
Header="My Tabs"
Style="{StaticResource HeaderStyle}"
/>
In Content template my all bindings working fine with viewmodel..But my problem is,in my header template here i have textblock and now i want here some content control and binding two different views here and show it according to requirement..
Any help??
|
|
|
|
|