Better overview of visual WPF resources - c#

Given: there are several resource dictionaries in WPF solution with various resources (vector graphics):
<ResourceDictionary ...>
<Canvas x:Key="SvgWarning" ... />
<Canvas x:Key="SvgError" ... />
<Canvas x:Key="SvgOk" ... />
...
<Path x:Key="PathBullet" ... />
<Path x:Key="PathMinus" ... />
...
Dictionaries are added to application resources. Those vector graphics are then used in different windows, user controls, etc.
Problem: over years of development they become too many. It's hard to tell how exactly which one looks like and I'd like to have better overview of them. E.g. if I'd have jpg-files referenced by a project then I could simply use windows explorer to preview how each looks like.
Currently I have to remember (or find) keys and then type it:
and only then I can see how it looks like. Silent intellisense is not a real problem (but a bonus points of course), because I simply want to preview images even before I decide to add one to a button.
Question: how can I organize it so I can quickly see which "witch" is which?
I can make a designer-only window (not used at run-time) and add all images there MANUALLY; by clicking each I can then see its key in xaml. Can I enumerate resources, detect which one is image (but not e.g. a style) and add it to such window? Maybe the way it's organized now is bad?
I don't need a concrete solution, rather a push in the right direction, hints from someone who has similar problem and have solved it.

Related

How to make user control like application bar - windows phone

My question seems to be a bit strange. I have a long list selector and I want to add a control like application bar in it so it can be repeated many times the same with the controls in the item template. I thought about a grid with the contents I want, but how can I make this Grid slides up and down ?
Yeah, it is strange but you can certainly try it. There is no definite way to do this but you can create a user control that would be the application bar like element you want and add it to the list selector. But the biggest problem is make it slide up and down. In the user control you can do this easily but there are many ways you can do this. You have to try it out and see. Use animations and story boards to animate the sliding effect. This can be done using Blend for Visual Studio. But you might run in to a problem where even though you did the animation of your application bar sliding in your Application bar like user control, it might not work in the list selector because the layout and the size of a single list item needs to change as the user expands the user control to have the sliding effect. As i said, there are many ways one can do this. You have to try it out and build it.
List item
In App.xaml type in this code
<Application.Resources>
<shell:ApplicationBar x:Key="UserControlAppBar" ForegroundColor="White" BackgroundColor="Black" IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton x:Name="button1" IconUri="/Assets/Images/appbar/img1.png" Text="News" Click="button1_Click"/>
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem x:Name="MenuItem" Text="Menu1" Click="Menu1_Click"/>
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
</Application.Resources>

Keeping Window "Docked" In Same Place C#/Wpf

I'm working on a windows wpf app to do fluid modeling using an open source engine called epanet. There is already an open source UI written in Pascal, we are trying to create one like it with added features and usability.
I want the app to start and have a main window with a couple tool bars and 2 separate sub-windows inside, as in the original epanet UI software (take a look at some of the screen shots in the link below). What is the best way to go about this?
http://engineering.wayne.edu/wsuwater/hydraulics/epanet.php
I tried using "popup" from this forum post:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/bf51e572-b41e-487b-99d0-95262899ef2c/
It was far to finicky and hard to control. Instead, I just created a new window and had it open after the MainWindow() class is loaded.
InitializeComponent();
DrawingArea Init_Canvas = new DrawingArea();
Init_Canvas.Show();
This works great, other than that the user has to manually adjust it to the right size and placement every time.
How do I go about getting it stay tidily tucked in the corner?
I'm not positive I understand the question but it seems like you need to display controls on top of one another. I too ran into problems with popups too and used this code as an alternative:
<Grid>
<Canvas Grid.Row="0" Grid.Column="0">
<TextBlock FontSize="55">One</TextBlock>
</Canvas>
<Canvas Grid.Row="0" Grid.Column="0">
<TextBlock FontSize="55">Two</TextBlock>
</Canvas>
</Grid>
Basically you set both controls to be row=0 and column=0 and they will display on top of one another. Maybe this doesn't meet your needs, but it is a nice trick.

Problems with adding EnumMatchToBooleanConverter to my xaml file

I am trying to follow this radiobutton tutorial
I created a class called EnumMatchToBooleanConverter and it is in the top level of my wpf project. It says to place the inside a window.resources like this:
<Window.Resources>
<EnumMatchToBooleanConverter x:Key="enumConverter" />
</Window.Resources>
I am using it in a usercontrol so I have placed it inside a stackpanel instead:
<StackPanel.Resources>
<EnumMatchToBooleanConverter x:Key="enumConverter" />
</StackPanel.Resources>
I have Microsoft Visual Studio Ultimate 2012 and it gives me an error:
EnumMatchToBooleanConverter is not supported in a Windows Presentation Foundation (WPF) project.
Any ideas as to what I am doing wrong? Am I not allowed to place it inside a stackpanel.resources?
I just tried placing it inside a grid.resources
<Grid.Resources>
<EnumMatchToBooleanConverter x:Key="enumConverter" />
</Grid.Resources>
and it says
The type 'EnumMatchToBooleanConverter' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
Well it is in the same namespace as the rest of my project, so I'm unsure why it isn't finding it.
Change
<EnumMatchToBooleanConverter x:Key="enumConverter" />
for
<local:EnumMatchToBooleanConverter x:Key="enumConverter" />
All non-built-in classes you reference in XAML must be prefixed by their corresponding xmlns prefix.
HighCore's got it right. Just to add to this namespace discussion, I thought I'd point out another approach that can help make the code more readable or help you diagnose where certain Controls/Value Converters/etc are coming from (i.e., which assembly they are really coming from). This technique could allow your XAML to appear like Christian has it in his blog (without the xmlns prefix):
<EnumMatchToBooleanConverter x:Key="enumConverter" />
Essentially you perform some some namespace mappings to consolidate namespaces like this (only works if the files are in a different assembly/project). So in my example above you have mapped one of your namespaces to the default xmlns, so you would not need any prefix in the XAML.
I'm still trying to figure out how far to take this technique and Paul Stovell talks about taking it to the extreme, like I've shown above.
Even if you don't end up applying it to that degree, knowing about it might come in handy if you're looking at someone else's Xaml and they have applied a mapping like that. Knowing that would remind you to lookup the AssemblyInfo.cs file and check for the mapping and possibly help you track down where a Control/Value Converter/etc is actually located.

Show obsolete/deprecated class usages in XAML

Context
We had quite a big memory leak in a WPF application we are developping that was caused by the use of DropShadowBitmapEffect in a resource library.
The drop shadow was used by some UserControl and by all our menus to cast a shadow over the actual content of the window, as such:
<DropShadowBitmapEffect x:Key="PopupDropShadow" ShadowDepth="1.5" Softness="0.15" />
...
<Rectangle BitmapEffect="{StaticResource PopupDropShadow}" ... />
I had to profile the application for many hours before I actually found the cause of the problem. The DropShadowBitmapEffect class is unmanaged and prevents objects from being GC'd. Also, you'll note that the DropShadowBitmapEffect class is marked as Obsolete, and that there is an updated class named DropShadowEffect that fixes the memory leak (and is also hardware accelerated thus improves render performance a whole lot). Here is the actual fix:
<DropShadowEffect x:Key="PopupDropShadow" ShadowDepth="1.5" />
...
<Rectangle Effect="{StaticResource PopupDropShadow}" ... />
Question
Is it possible to have the deprecated/obsolete class usages throw warnings on compile when used in XAML in Visual Studio 2010?
I haven't tested it for XAML but Gendarme has a rule that checks for the use of obsolete code.

Best practices for designing a simple element to be used in many places, WPF

What are the best practices for designing a simple component, for example a border with a background, rounded corners and a textblock with specific styling inside? What I need to be able to do is add this component on many different objects (basically a styled label for the items). The easiest way to design such a thing, in my opinion, is via XAML, but how do I create more of these objects from the code behind?
Another option would of course to just write it all in code, but it is much slower to design the look by just looking at code. I tried googling around a bit but I suppose I am simply not figuring out the correct keywords because I was unable to find anything of use.
I think there are multiple ways of doing this. Depends on what exactly you want to achieve. You would want to read up on the following in WPF
1. UserControls
2. CustomControls
3. Styles
4. Templates
5. Resources
You could use a ContentControl and set its template. Your template would be the border/background/rounded corners etc...
<DataTemplate x:Key="MyTemplate">
<Border>
...
<TextBlock Text="{TemplateBinding Content}" />
...
</Border>
</DataTemplate >
You'd use it like this:
<ContentControl ContentTemplate="{StaticResource MyTemplate}" Content="blah blah" />

Categories

Resources