I have an user control which has a treeview. This user control inherits from a base user control.
I was able to see the arrows in the treeview well till I changed the base control graphics.
From that point I started to see strange squares instead of the regular arrow in the treeview.
Is there any reason for this behavior?
This behavior was influenced by a style that was defined in the app.xaml.
The target type of the style was Border.
Probably the type of the arrows in the treeview is some border, and the public border type in the app xaml caused those arrows to be changed.
Related
Is it possible to use the parts of default WPF controls for binding?
Specifically, I'm aiming at binding the padding size of a ListBox control to the width of the arrow part of a ComboBox control.
Using VS 2015 Live Visual Tree, I can see that the specific part I'm interested in is named 'splitBorder', which is the portion of the ComboBoxToggleButton that contains the downwards arrow symbol.
Specifically, I'm aiming at binding the padding size of a ListBox control to the width of the arrow part of a ComboBox control.
No, you can't really do this since the width of the arrow and the arrow itself is hardcoded within the ControlTemplate of a ToggleButton that is part of the default ControlTemplate of the ComboBox.
You cannot bind to the arrow Path from any element outside of the control template where it is defined and the ComboBox class doesn't expose the arrow from any public property that the ListBox can bind to. So this is not possible I am afraid.
I'm developing a WPF project where I need to validate textboxes on code-behind and then change the border color of those textboxes to some unknown color defined by the user configuration; the problem is that to overwrite the MouseOver effect I would need to set the value from XAML directly via ControlTemplate or Style.
Is there a way to get the current value assigned to the TextBox from XAML? Maybe binding it to itself?
I will appreciate any help you can give.
When validating a TextBox, or any control for that matter, it's common to use an adorner to display the validation error (in your case, setting the border color). You can have a look at an example here.
Using this method, you don't actually change the TextBox's border, but create a new visual layer on top of the TextBox that draws the new border around it. This is pretty much the way validations should be done in WPF, and it also solves your problem of having to deal with changing the TextBox's border value back and forth.
I'm wanting to have a tooltip for disabled TabItems in a TabControl. The standard way of putting tooltips onto disabled controls in Silverlight is by wrapping the control in a dummy element that has the tooltip, but I can't get at the TabItem like that. The TabItems' host control is a TabPanel, which doesn't seem to expose any useful properties.
Any ideas?
I had the same problem with putting a Toolip on a disabled menu item, i solved it by changing the VisualState of my menu item to Disabled and then disabling the MouseButton events.
VisualStateManager.GoToState(tabitem, "Disabled", true);
You'll have to be careful with other events though, because the VisualState will change according to different events. It's not a perfect solution, but it will work for certain scenarios.
Hope this helps
My current workaround for my own problem:
I've got a TabControl Behavior that finds the "TabPanelTop" template part (or left, right, or bottom depending on TabStripPlacement), along with the "TemplateTop". I add a Canvas into the TemplateTop (which is a Grid), and fill it with Transparent Rectangles whose positions (using TransformToVisual) and sizes are calculated (and updated) to be the same as the TabItems, which are the children of the TabPanelTop.
The visibility of the Rectangles is bound to the inverse of TabItem IsEnabled, and the ToolTipService.ToolTip is bound to the ToolTipService.ToolTip on the TabItem.
It's a bit scary but it works and is easy to use.
I am trying to achieve functionality similar to that of a Popup, without using a Popup, but instead adorning my ContentControl with a basic adorner. Basically, I want the ContentControl to have an "overlay" effect, whereby it is the topmost object, above all other elements - similiar to that of the Popup control.
Here is the problem that I am running into, and I am hoping that someone can point out where I am going wrong:
I have a stand grid with two row definitions. The first row contains a UI element - for example, a rectangle. The second row contains a custom control that I have developed to emulate the functionality of a "drawer" sliding out. Basically, when I click on button, I am going to animate a TranslateTransform to "slide" my ContentControl "up". This works fine - except that it gets cropped underneath the rectange in the first row of the grid. If I remove the row definitions in the grid, then when the desired behavior is achieved - the ContentControl is moved "up" and partially "on top" of the rectangle. The rectangle is merely a place holder for what I am trying to achieve. I basically want to have a drawer type control that can slide out and be on top of all other controls.
I am somewhat new to using the Adorner class, so, I am hoping that someone can please point out where I am going wrong.
Thanks.
Chris
Change the parent of the adorner to the full grid, and not just your control. If you put a control in a grid row, and set the adorner to adorn the control, it will usually be clipped to that row because the control is.
I am confused with learning about WPF. I see ControlTemplate used to determine how each item in a listbox looks. Isn't that what the ItemTemplate is used for in listboxes? What is the difference?
A ControlTemplate let's you change the look&feel of existing controls, for example, make a normal everyday button look like Vista's taskbar shiny glass buttons or make a tab control look like the new Office 2007 ribbon.
The idea is that the control contains only the behavior and the ControlTemplate contains the look&feel - so a button is "something you click" not "a rectangle with some 3d effect you can click on".
You can replace the ListBox's control template to get something like a list box with rounded corners or custom scroll bars.
A DataTemplate (ItemTemplate is a property of type DataTemplate) on the other hand let's you control how the data rows displayed inside list boxes (and other similar controls), data templates are used to specify things like "Show last name, than a comma and the first name - and the last name should be bold and the first name should be green if it starts with an A".
And just for completeness there is also an ItemsPanelTemplate class that is used to change the internal layout of a list box - Charles Petzold's WPF book has an example of using it to make a normal list box display it's items in a circle.
An ItemTemplate describes how to render the data item in a listbox (for example, you might have your listbox bound to a List - the ItemTemplate will allow you to specify how to render a Foo). An ItemTemplate is a DataTemplate.
A ControlTemplate describes how the ListBox itself should be rendered