Is there a way to force the XAML designer to expand and show the contents of an ExpanderView?
I have tried setting the IsExpanded property to true as well as binding it to one of my Design ViewModels that sets it as true and neither method worked.
Related
I discovered today that when I style something in XAML, if I leave the FontFamily out, it will inherit it from the closest ancestor that has a FontFamily. How is it figuring out which element to reference?
<Page
...
Foreground="Green">
<ContentControl Foreground="Purple">
<TextBlock Text="I am purple unless ContentControl Foreground is not set."/>
</ContentControl>
</Page>
My First thought was that it was using the DataContext somehow, but if the reference object isn't the data context, it still inherits these properties.
I tried googling it, and got a lot of links showing me how to set the Background in a style, but I want to understand how it works when unset...
I can't figure out which UI framework you are using, UWP or WPF. So I write them both.
For WPF, you can read Property Value Inheritance | Microsoft Docs.
For UWP, you can read Dependency properties overview - UWP app developer | Microsoft Docs.
For both WPF and UWP, this kind of property is DependencyProperty. The property value you keep unset is from multiple sources.
WPF
Property system coercion.
Active animations, or animations with a Hold behavior.
Local value. The value you set in your XAML code.
TemplatedParent template properties.
Implicit style.
Style triggers.
Template triggers.
Style setters.
Default (theme) style.
Inheritance. The value you just find out from the ancestors.
Default value from dependency property metadata.
UWP is much simpler
Animated values.
Local value.
Templated properties.
Style setters.
Default value.
You write your own dependency property of WPF as an inherited property, but you cannot do the same in UWP.
I have a ComboBox with thousands of items bound to it.
The problem I'm facing is when I run the app on a tablet the scrollviewer's scrollbar is very thin hence I cannot hold and drag it and can only swipe to move inside the ComboBox.
Hence I was wondering is there a way to change the style template of the ScrollViewer inside the ComboBox inorder to make the ScrollBar width larger.
You'll have to dig in to the style template and change some hard set properties for Width / Height that sit on the parts like the Thumb that you will find on the default style template. You can extract a copy via selecting a Scrollbar -> Right Click -> Edit Style -> Edit a copy. Save the copy wherever you need it, like a resource dictionary if you plan to use it multiple places or to the instance where you need it.
(Note: Generally folks start at the ScrollViewer level, then find a Scrollbar in it, and apply the style changes there so they can apply the style directly to ScrollViewers)
Once you have your changes made to the control template you then need to pass them to your ComboBox. If you only need it for the one ComboBox, You can just put the style template in it's Resources and remove the x:Key name you gave it so it hits the instance of the TargetType via inheritance for just that ComboBox.
However if you want it to hit EVERY ComboBox, then you'll need to edit the ComboBox style template and add a reference to the Style template you just made to it's embedded ScrollViewer.
You'll find long tutorials out there for stuff like WPF/Silverlight that pretty much the same concept but little nuance differences in the templates and syntax of properties.
Hope this helps, give it a shot and if you get stuck come on back and we'll get you sorted.
I've got a WrapPanel which will contain several different custom UserControls. Depending on the scenario, I may need to filter down which UserControls are visible. My goal is that I can switch which controls are visible on the fly by showing/hiding the controls that need to be filtered - thus shifting the controls that are left showing, to the top-left of the panel.
Right now I am simply setting the Visibility property of the control to Visibility.Collapsed when I don't want them to appear. I thought that because I was using a WrapPanel, the rest of the controls would shift to the top-left of the panel.
Instead, after hiding some of the UserControls, the controls that are still visible stay exactly where they were before, and I am left with gaps between the controls that are still showing. I've opened my app in Silverlight Spy, and it shows that the UserControls are still actually there (which makes sense) but are simply invisible.
So my question is:
Is there a way that I can show/hide UserControls within a WrapPanel which allows the still-visible UserControls to slide to their new positions (all shifting towards the top left - similar to a StackPanel)?
I've debated removing the UserControls completely from the WrapPanel (I think this would work) and storing them in memory until they are needed. Then if I wanted to show/hide other controls, I would get them from my in-memory object. It seems like there should be a better way to do this though.
If anyone has any suggestions or advice, it would be greatly appreciated. Thanks!
-Lloyd
UPDATE:
XAML: (very simple)
<toolkit:WrapPanel x:Name="MyLayout" Height="300" HorizontalAlignment="Left" VerticalAlignment="Top" Width="400" />
Code-Behind: The UserControls are getting added dynamically:
MyLayout.Children.Add(oUserControl)
And they are getting set to collapsed dynamically as well:
oUserControl.Visibility = Visibility.Collapsed
I think I've found the problem. We added the WrapPanel to a ScrollViewer recently, and when I took the ScrollViewer out I was able to achieve the functionality I wanted.
I'm not sure why the ScrollViewer would have that effect though?
Also, I've found that I can leave the ScrollViewer in place and simply call .Measure() on the WrapPanel to update the layout.
Neither option makes 100% sense to me, but they do both seem to work.
I have the following question:
The current project I'm working on is full of inherited controls, allowing us to tweak the behavior a bit in comparison to the default behavior. Now i created a sort of notification control (composed of an image an tooltip control) which I want to add to most of our control collection. This would allow usage of thise notification anywhere we need.
I tried dragging my own control to the design view of the inherited control and I pass on the properties that should be set on my own composed control.
Rendering however seems to be a problem. Since the original control is an inherited control, the size of that control can vary. My notification should be appearing behind the control:
[control][notification]
control being the inherited control, notification being my own control.
Is this possible on the inherited control? The only other option I see is making 2 versions of the control, one clean inherited and a composed one with both (in which case I would need to relay all databindings, which I don't want).
As I understand it, a Panel isn't meant to have any visible "chrome." The StackPanel, Grid and Canvas don't have any visible elements (with the exception of the gridlines, which they say are only for debugging layout.)
In my example, I am going to create a Custom Panel that uses Attached Properties to lay out its children controls. However, I want my Custom Panel to present a visible "grid" of sorts in the background. The look of the grid (sizing and positioning) will depend on the size and position of the child elements.
What are some of the ways to achieve this? Being very new to Silverlight and XAML in general, my first guess was to create a Custom Control which includes my custom panel for layout.
I think I'll be able to figure out the specific code, but I need to be pointed in the right direction in terms of what building blocks are appropriate for this scenario.
You are correct that custom Panels cannot show any extra chrome; they can only display their Children (Grid being an exception).
To do what you want to do, you could create a custom Panel which just adds extra Children to display the chrome. This would not be a good design though (since users of the Panel would see these extra items in the Children collection).
The best idea is to do what you said: create a custom Control that exposes a Children property. This control could internally use a private custom Panel to lay out these elements (e.g. TabControl uses a special TabPanel for laying out the tabs). In the Controls default template, you might want to use TemplateBinding on the Panels' Children property to your Control's Children property.
Panel can add Adorners to its children, read this article about adorners: http://msdn.microsoft.com/en-us/library/ms743737.aspx