ContentControl WPF does not display Content - c#

I've convertet the Project from https://silverlightcontrib.codeplex.com/ to WPF (github https://github.com/jogibear9988/silverlightcontrib) to get EMF/WMF metafile support in WPF.
Now my Probjem is, the EMF Class uses a ContentControl for displaying it's Content. The Content is also set, but nothing is displayed. If I check it in WPF-Inspector, I see that the EMF Control has it's Content listed in the "Logical-Tree" but not in the Visual! Can anyone help me out with this?
The current state of the Fork is Online (if anyone will look at the Code!)
If I look in snoop everything seems alright:
You see, the Content Presenter has a Content set and Filled, but it does not get into the Visual Tree...
Here is the Logical Tree from WPF Inspector:
And here the Visual:

I am not very familiar with Silverlight, but in WPF when you override MeasureOverride(...) and ArrangeOverride(...) you have to measure and arrange the contol's children so they can measure and arrange their children and so on.
In your case, you have to include calls to base.MeasureOverride(...) and base.ArrangeOverride(...) in the Emf class that inherits from ContentControl.

The two most likely issues are that your ContentControl is using a ControlTemplate that has no ContentPresenter (on one that is specifically using something other than the default Content property) or that it is using an empty DataTemplate as its ContentTemplate. You should be able to check either of these by inspecting at runtime.

I haven't quite figured this out, but it's something to do with the sizing. In Snoop it is showing a RenderSize of 0,0 and in inspector the actual height/width is also showing as 0 - you can see the red highlight inspector draws around the element is a small dot rather than a rectangle. I am guessing there's some Silverlight specific behaviour in the EMF control that doesn't port directly to WPF.

Related

Drawing Adorner of a UserControl without clipping but over controls below

I have fields in a document that are displayed as UserControls in a WPF Window (inside tabs).
I needed to make an autosearching feature that displays results below the field.
I went with a adorner containing controls inside (a list).
The first problem is that I could not access the adorner layer for a control inside a UserControl.
I went with finding the AdornerLayer of the Window. Unfortunately if I put the adorner inside it I would not see it anywhere.
The next attempt was to put an AdornerDecorator inside the UserControl.
This worked fine if I was drawing the adorner above the control:
However if I was to put the adorner under the text field the controls below would be drawn above the Adorner:
Is there a way to make this second "below" case work properly?
Have you tried using a Popup already? Popup is also what the ComboBox uses afaik, so i think thats pretty much what you are looking for.
I guess you will not get the decorator to work as long as you add the below items after the textbox, so the will always have a higher zindex. Maybe setting Panel.ZIndex property works, but i think thats a pretty dirty solution.

Width of control based on width of window

I'm trying to figure out, how to write Responsive UI in XAML.
I would like to have 2 controls on my window. MinWidth of each control id 400.
If Width of windows is >800, Width of each control should be 50%, if we change widht of window to <800, each control should have 100% of window.
It's pretty simple to set up something like that with HTML/CSS, and right now I'm trying do it in WPF without progress.
Can you help me with that?
I tried to handle that with WrapPanel, but it does not work. It wraps properly, but does not change width of control.
I have two ideas for doing this:
Using a binding converter, and bind the width/height of each item to the container width/height.
Creating a custom panel, with de desired layout.
Only a few ideas, hope helps.
Define resources based on screen revolution.
In design mode, using dynamic key to avoid errors.
In runtime, dynamically add resources into App.

Windows store app, horizontal scrolling when too much text

I am making an app for the Windows store (xaml/c#), in this app i create a list of properties of a file. One properties is the file path, this is always too long. my solution would be to make this side scrolling when this textblock is selected.
the text would start to scroll when selected to make all the information readable. (ticker bar)
I can’t find a property to achieve this, and I find it difficult to make a custom function for this. Can you help me?
I'd reconsider the idea. I had the idea many times and it was always rejected by designers. I think animating text is likely to be more annoying than clipped text. A better way might be to either wrap it in place or if you are in a list with limited item height - only show the full text after it was tapped - either with some popup or in the details view of the tapped item.
Having said that - to animate it you'd put the TextBlock inside of a Canvas, set the Clip of the Canvas to a RectangleGeometry that defines your clipping region (and update it on size updates), then animate the Canvas.X property of the TextBlock. The problem with that is that Canvas.X is not an "independent" property and so you'd need to set DoubleAnimation.EnableDependentAnimation="true" on the animation and could still get a fairly choppy animation.
A better choice might seem to be to animate the RenderTransform of the TextBlock (e.g. set it to a TranslateTransform and target the X property of the transform in the animation), but last time I checked - this could animate the TextBlock in an already clipped form, so you still wouldn't see the part of it that doesn't fit on screen. You could try that though.
Putting the TextBlock in a ScrollViewer might work better, but it would suffer from similar problem as the Canvas solution since the ScrollViewer doesn't even have an animatable offset property. In Windows 8.1 you get built in animations when you call ScrollViewer.ChangeView(), but that would likely animate too quickly. It is possible with the help of a proxy dependency property or other per-frame dependent animation as in the ScrollToHorizontalOffsetWithAnimation() ScrollViewer extension method in WinRT XAML Toolkit.

Is it possible to have an outline and padding/margins of all containers in WPF?

This is something that would be very useful during development. For example, my android phone allows "Show Layout Boundaries" as a Developer Option, e.g.
With this, I can see outlines of all layouts, including the padding and margins. Is there something like this in WPF that I could use to see how each element on the screen relates to the other elements?
In WPF the only thing that seems to be close it is ShowGridLines property in Grid:
Enabling Grid lines creates dotted lines around all the elements within a Grid. Only dotted lines are available because this property is intended as a design tool to debug layout problems and is not intended for use in production quality code. If you want lines inside a Grid, style the elements within the Grid to have borders.
Example:
<Grid ShowGridLines="True" ... />
For more information, see this link:
ShowGridLines Property Allows You to See Individual Cells in Grid
While the program is running, you might be interested in Snoop, which lets you inspect and highlight arbitrary elements of the interface and explode the window into a 3D view. It's not the same visual as you're looking for, but similarly useful.

Button Styles via xaml and expression blend

I created a custom control that looks a lot like the tab buttons in VS 2012. In my control I could set a propertiy to posistion the text and sidebar vertical or horizontal. After playing around with the control I figured there was probably a better way to go about this. So i fired up the Expression Blend preview and suprising enough (only second or third time using blend) was able to create a style to achieve a simliar style button. However, Now I want to have control over the text and sidebar being vertical or horizontal. I would also like to have control over the mouse over color. Is this possible to do via one style or am i going to have to create a bunch of different styles?
If I understood correctly you can achieve what you want to do with event triggers.

Categories

Resources