|
Collin Jasnoch wrote: the namespace would get included anyways (wouldn't it?)...
You'll need to actually look at the xaml and code-behind to determine that.
Collin Jasnoch wrote: I just don't see how to trigger off a click.
What does that mean? You want to simulate a click? Use an event trigger
to do something in response to the Click event? Respond to a click event
in code-behind?
Collin Jasnoch wrote: I had posted the actual one earlier but it was REALLY long
So forget all the fancy stuff you did with your button...
Make a canvas: <Canvas Width="100" Height=20 Background="LightSteelBlue" />
Use Blend's "Make Button..." to make a button from that canvas.
Use that button in another user control like you want to, including showing WHERE
you want a click event handled.
Now post the actual xaml and code (which will be very small) so we don't have to guess what
you're trying to do
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
Collin Jasnoch wrote: I thought that is what I had posted...
Maybe....that doesn't mean I understood it
Anyway this is excellent, thanks. Now I see what's going on.
First of all, since your custom button is wrapped in a UserControl, its
events are no longer available at the UserControl level, so that's why
you can't get a Click event from the UserControl. This is one of the reasons
why a UserControl is the least flexible way to make a custom control....
UserControl is best suited for entirely self-contained controls.
There's a variety of ways around this - here's a few...
1) instead of wrapping a custom button in a UserControl
and instantiating a control of that UserControl type, just cut/copy the
button style that Blend created ("ButtonStyle1") to an appropriate place in
your app's resources, and anywhere you want an instance of your custom button,
instantiate a regular Button using that style, e.g.:
2) Leave it the way it is and add a public Click event to the CustomButton class.
This event should have the same signature as the ButtonBase class' Click event.
Add a Click event handler to the button in in the CustomButton user control.
In that handler, which will be in the CustomButton class, fire the event you added
to the CustomButton class....you'd be effectively just forwarding the event.
3) Go the full custom control route: Control Authoring Overview[^]
Method 3 is rarely necessary.
Method 2 has the limitations of a UserControl (e.g. users of the control can't
re-template the control to customize it) but it's the simplest to code.
Method 1 is also simple, and a very common way of customizing controls.
More info on options for customizing controls here: Control Authoring Overview[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have an ObservableCollection bound to a list box - the collection is essentially ObservableCollection<person> where Person has 2 properties: Name and Age. How do I bind the currently selected item in the listbox to some textboxes (seperate from the ListBox) which show the Name and Age of the Person and allow the Name and Age to be updated using the TextBoxes?
|
|
|
|
|
The easy way to do this is to set IsSynchronizedWithCurrentItem="True" on your listview. This way, the currently selected item is synchronised with the collection.
"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
|
|
|
|
|
|
Thanks for that, but I already know what to do. I assume you meant to link this to the OP rather than me.
"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
|
|
|
|
|
Sorry, thought it backed up your comment of using IsSynchronizedWithCurrentItem="True"
|
|
|
|
|
I saw it - thanks.
modified on Monday, May 11, 2009 12:48 PM
|
|
|
|
|
Set IsSynchronizedWithCurrentItem="True"
I agree
Niladri Biswas
|
|
|
|
|
Hopefully this will be an easy one for someone to answer!!
I have a class (CollectionsViewModel) with a static properity in (they dont have to be static), which return a List.
I want to call the propertiy in xmal to set my itemsource of a combo.
Here is what i have
ItemsSource="{Binding Source={x:Static collections:CollectionsViewModel}, Path=GetQueueCollection}"
where collections is defined as the namespace of CollectionsViewModel class
I can't set the CollectionsViewModel to the datacontext, as that is set to another class
Any help/links most welcome
Mark
|
|
|
|
|
|
|
Hi,
For a project concerning a planning application, we encounter major WPF performance problems.
The application has to show a grid-like presentation of persons on the Y-axis and dates on the X-axis,
and every "cell" represents a duty or task for the person on this date. The presentation of one cell is graphical,
drawing a rounded rectangle and some lines and text.
Now we have to be able to show a full month for around 200 persons, yielding a total of 6000 cells. (so this means 6000 rectangles, 24000 textblocks, 12000 lines). Of course this is not shown onscreen all at once, only around 5 days on the X-axis and 10 persons on the Y-axis (so 50 cells at once on-screen)
we have tried a multitude of approaches, ranging from drawing everything upfront in a grid/canvas within a scrollviewer. It takes over 10 seconds before anything is shown on screen (no doubt due to the layouting) but once
it was shown, scrolling was really fast.
Then we tried an approach with itemscontrols/listbox of listboxes/virtualizing stackpanel, which made that the grid
was initially shown much faster, but then scrolling was unacceptably slow.
Can anyone give some starting points on how to tackle this problem ? We looked at some third party grid controls,
and also the WPF toolkit grid on Codeplex, but it feels like this would not be an adequate solution to our problem.
Kind regards,
Sven.
|
|
|
|
|
Hi,
I have made custom shapes that the user can draw on a canvas. Now I want to add an adorner around the shape when the user selects it. Normal I use the DesiredSize property to get the size of the element that I want to adorn (in this case the shape). The problem is that de desired size of my custom shapes start at the origin of the canvas (0, 0). The endpoint is correct (bottom-right point of the shape).
Does anybody knows how I can solve this so the startpoint is the top-left corner of the shape?
Thanks,
Bart
PS: I draw the shapes in "protected override Geometry DefiningGeometry"
|
|
|
|
|
|
Good people,
How do I enable a TextBox to allow empty returns. For example, when I press enter, it will allow a new line or blank lines if I press it multiple times.
Sort of like what I did to get to this new line, I just pressed enter a few times.
Thanks for any information you can provide.
Blitz
|
|
|
|
|
Set the following properties in your textbox TextWrapping="Wrap" AcceptsReturn="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
|
|
|
|
|
Thanks, I really appreciate it.
Blitz
|
|
|
|
|
Hi,
WPF is still a nerw technology for me and now I am in trouble with static ressources.
Actually:
I've made a TextBlock which should be changing its static ressource on click event!
So I have made two styles.
1. Style x:Key="CalendarDayStyle" TargetType="TextBlock"
2. Style x:Key="SelectedCalendarDayStyle" TargetType="TextBlock"
The TextBlock normally is set to
Style="{StaticResource CalendarDayStyle}"
Trying things like
((TextBlock)sender).Style = Style="{StaticResource SelectedCalendarDayStyle}";
is not working.
How can I solve this. Maybe I am wrong and static resource can not be changed from code behind.
cu s00n
eXi
|
|
|
|
|
Keep in mind that the "Style" property is still a property that takes a Style instance. The StaticResource markup extension is just a helper class that looks up a named resource (of type STYLE) and assigns it to that property.
Accordingly, in code, you need to look up the style resource yourself and assign it - StaticResource is nothing you are using at this time. What you are looking for is the FindResource method.
However, changing a style in code behind to switch the look when a textbox is selected is not the WPF way of doing things. Usually, you just write one style and use triggers to exchange the look as soon as the textbox is selected. Do a short Google search - there are tons of samples around.
hth, Philipp
NetDrives - Open Source Network Share Management Awesomeness
|
|
|
|
|
Thank you for pointing us in the right direction.
|
|
|
|
|
You can change a resource from code behind, but it's important to understand that XAML code in {} sections is actually syntactic sugar for a fairly complex binding mechanism. What you would need to do would be to use FindResource to find the appropriate resource and apply it.
A better way (and the correct WPF way) would be to apply a data trigger to the Click event where you applied the style in the XAML. This has the advantage that the WPF binding mechanism would only apply the style while the item was clicked - it resets it once the click has finished.
"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
|
|
|
|
|
Suppose I have a resource file like this
<UserControl.Resources>
<Style x:Key="LightGrayBackground" TargetType="{x:Type igEditors:XamTextEditor}">
<Setter Property="Background" Value="LightGray"></Setter>
</Style>
</UserControl.Resources>
Now I will access this
TryFindResource("LightGrayBackground") as Style
Niladri Biswas
|
|
|
|
|
try this
TextBlockID.Style = DirectCast((App.Current.Resources("CalendarDayStyle")), Style)
your app like this
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Assets/Styles.xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<Application.Resources>
|
|
|
|