Using a properties grid with a tree control - wpf

I want to create a tree control that when the user clicks on an element in the tree control, a properties grid is populated with its properties.
I've created a tree control as a user control and I'm using Jaime Oliveras' property grid. I have both on a WPF window but I can't seem to figure out how to make the two communicate with each other.
The XAML on the Main window is:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:advanced="clr-namespace:OptionsStrategyTree.ViewModel"
xmlns:local="clr-namespace:OptionsStrategyTree.ViewModel"
xmlns:Controls="clr-namespace:System.Windows.Controls"
x:Class="OptionsStrategyTree.MainWindow"
mc:Ignorable="d"
Title="MainWindow" Height="400" Width="500">
<Grid>
<local:UserStrategyTree HorizontalAlignment="Left" Margin="18,6,0,13"
Width="195" Height="340" />
<Controls:WpfPropertyGrid x:Name="StrategyTreePropertyGrid"
HorizontalAlignment="Left" Height="340" Margin="233,6,0,0"
VerticalAlignment="Top" Width="239"/>
</Grid>
</Window>
I've had this properties grid working nicely when the controls are all on the same XAML window. But when I've created a tree control as a user control, it's a separate entity in its own XAML space that seems to be isolated from everything else. Is there any way to connect the two?

Related

How to center BusyIndicator to the center of MainWindow?

I created sample Wpf application and installed Extended WPF Toolkit (NuGet package). Here's my xaml code for showing BusyIndicator.
<Window x:Class="WpfApp3.Progress"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:local="clr-namespace:WpfApp3"
mc:Ignorable="d"
WindowStyle="None"
BorderThickness="0"
Title=""
VerticalAlignment="Center"
HorizontalAlignment="Center"
SizeToContent="WidthAndHeight"
d:DesignWidth="300"
d:DesignHeight="300">
<xctk:BusyIndicator IsBusy="True"
HorizontalAlignment="Center"
VerticalAlignment="Center"></xctk:BusyIndicator>
</Window>
Showing the progress window is triggered with this code:
private void Button_Click(object sender, RoutedEventArgs e)
{
Progress w = new Progress
{
Owner = Application.Current.MainWindow,
WindowStartupLocation = WindowStartupLocation.CenterOwner
};
w.Show();
}
My question is simple. How to show BusyIndicator in the middle of the MainWindow screen. As Shown from the picture below it's not centered as it should be. Note that I use SizeToContent="WidthAndHeight"
Having a seperate window to display the busy indicator and will result in unwanted behaviour. What happens if the original window is maximised, moved etc.?
Consider adding the busy indicator to the main screen. Usually I create an overlay region that is used to display message dialogs, progress bars etc..
<Window>
<Grid>
<Application stuff ....>
</Application stuff>
<ContentControl regions:RegionManager.RegionName="OverlayRegion"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" />
</Grid>
</Window>
I'm using Prism here but you can replace the ContentControl with anything, such as the BusyIndicator and manipulate the visibility of the control.
Solved it by removing Window.SizeToContent property and by adding VerticalAlignment and HorizontalAlignment properties to BusyIndicator (actually now I used spinner, but this doesn't make any difference in solution).
<Window x:Class="Test.Progress"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
WindowStyle="None"
AllowsTransparency="True"
BorderThickness="0"
Title=""
WindowStartupLocation="CenterOwner"
ShowInTaskbar="False"
Background="Transparent"
d:DesignWidth="200"
d:DesignHeight="200"
MaxWidth="250"
MaxHeight="250">
<xctk:BusyIndicator IsBusy="True"
HorizontalAlignment="Center"
VerticalAlignment="Center"></xctk:BusyIndicator>
</Window>
The problem is because BusyIndicator was not designed to use it in separate window
The BusyIndicator is a ContentControl. What this means is that the BusyIndicator can contain a single child element within it?s open and closing tags.
Additionally if you do, first thing that is shown is small ui control (12x12 pixels) and after some latency finally the progress bar/busy indicator is shown.
By specifying SizeToContent='WidthAndHeight', xaml automatically resizes height and width relative to content. In this case (12x12) ui control is taken, and after some latency time finally as mentioned above busy indicator is shown. But by that time, the xaml ui renderer already applied SizeToContent and therefore you would have to manually re-position the progress bar.
I'm not really sure how xaml ui renderes works without specifying SizeToContent, but apparently it re-positions the busy indicator correctly after it is shown.

Images not appearing on buttons when user control is in referenced assembly

I have a main WPF application which references a WPF User Control Library that I created. In the library, I have one user control and an images folder (images used by user control). Here is part of the XAML that I have in the user control:
<UserControl x:Class="Alstom.UserControls.MainToolbar"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Alstom.UserControls"
mc:Ignorable="d"
d:DesignHeight="120" d:DesignWidth="3440">
<UserControl.Resources>
<Image x:Key="Subway" Source="/images/MainToolbar/Subway.png"/>
<Image x:Key="Globe" Source="/images/MainToolbar/Globe.png"/>
<Image x:Key="Gavel" Source="/images/MainToolbar/Gavel.png"/>
<Image x:Key="Clipboard" Source="/images/MainToolbar/Clipboard.png"/>
<Image x:Key="EllipsisVertical" Source="/images/MainToolbar/EllipsisVertical.png"/>
<Image x:Key="Check" Source="/images/MainToolbar/Check.png"/>
<Image x:Key="Bell" Source="/images/MainToolbar/Bell.png"/>
The user control has buttons which I wrote like the following (note that I defined the Content property as StaticResource:
<Button x:Name="button" Grid.Row="1" Grid.Column="0" Content="{StaticResource Subway}" HorizontalAlignment="Center" VerticalAlignment="Center" Width="48" Height="48"/>
When I double click the user control, in the designer, I see the images on the buttons.
But I created a main WPF application in my solution which references the external assembly like so:
<Window x:Class="MainToolBar.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:myMainToolbar="clr-namespace:Alstom.UserControls;assembly=Alstom.UserControls"
mc:Ignorable="d"
Title="MainWindow" Height="auto" Width="3440" ScrollViewer.VerticalScrollBarVisibility="Visible">
<Grid>
<myMainToolbar:MainToolbar HorizontalAlignment="Left" VerticalAlignment="Top"/>
</Grid>
When I double-click the MainWindow.xaml, I don't see the images on the button in the designer, nor when I run it.
What do I need to do to show the images at runtime? In the user control project, the images have a Build Action = Resource. But I tried to change one of them to Embedded Resource, and it still did not work.
What am I doing wrong?
Try to set the build action of the images to Resource and use a pack URI:
<Image x:Key="Subway" Source="pack://application:,,,/YourAssemblyName;component/images/MainToolbar/Subway.png"/>
Don't forget to change "YourAssemblyName" to the actual name of your assembly/WPF User Control Library project.
Pack URIs in WPF: https://msdn.microsoft.com/en-us/library/aa970069(v=vs.110).aspx

wpf crystalreport viewer dissappear for no reason

Well the problem is easy to explain and hard to figure out, at least by me, so i have a tabcontrol with 3 tabitem, on one of the tabitems i have a wpf reportviewer that loads a report of some data, when i change tabs, it does not matter to each one when i get back to the tab with the crystalreport in it, the crystalreport viewer is not there anytmore! i also have a button on top to refresh the report and the button is still there but the crystal report control is not there anymore!
my xaml looks like this
<UserControl x:Class="uccvrFactuur"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:my="clr-namespace:SAPBusinessObjects.WPF.Viewer;assembly=SAPBusinessObjects.WPF.Viewer"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Button Content="Report" Height="50" HorizontalAlignment="Right" Margin="5" Name="Button1" VerticalAlignment="Top" Width="50" />
<my:CrystalReportsViewer Name="crvFactuur" Margin="0,60,0,0" />
</Grid>
</UserControl>
i must say the first time i click on that tab the control is there but i change tabs and go back to it the control is not there anymore.
Thanks in advance

Changing Silverlight view

I am trying to create a extension from an existing view where I have a list of text controls and in the new project I would like to use this control and change one of these text boxes to a radio button.
Using MVVM makes it easy to use the same code without having duplicated code, but for the XAML view I find no good way to do this change without creating a copy.
Example:
Core project with the main user control
<UserControl x:Class="SilverlightApplication4.MainPage" Name="test"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel>
<TextBlock>
asdfasdf
this is a test
</TextBlock>
<Button Height="120" Name="asdf" Content="This is a Button">
</Button>
</StackPanel>
</Grid>
</UserControl>
Now I have a second project where I want to change the TextBlock to something else.
<UserControl x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
xmlns:core="clr-namespace:SilverlightApplication4;assembly=SilverlightApplication4" d:DesignHeight="300" d:DesignWidth="400">
<core:MainPage>
<!-- how do i change the type of child elements?-->
</core:MainPage>
</UserControl>
Solution will be to use a ContentControl and bind it to a ViewModel through Caliburn.Micro.
I added an example and code to my other question (below the XAML section): Project structure for EF/Silverlight application

Template of root control

I have custom control named Frame (public class Frame : ContentControl, IDisposable). Frame in constructor defines DefaultStyleKey = typeof(Frame); and Frame template is in Generic.xaml resource. Now In some other project I use frame that is in Silverlight.Controls and if I set my main page that the root element is frame like this
<ShellFrame:Frame x:Class="Modules.Adresar.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:s="clr-namespace:Modules.Adresar.ViewModel"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:ShellFrame="clr-namespace:Silverlight.Controls;assembly=Silverlight.Controls" mc:Ignorable="d"
DataContext="{Binding Source={StaticResource VMLocator}, Converter={StaticResource VMIndexerConverter}, ConverterParameter=AdresarVM}"
d:DataContext="{d:DesignInstance IsDesignTimeCreatable=True, Type=s:AdresarViewModel}" x:Name="MainFrame">
<Grid x:Name="LayoutMain">
</Grid>
I can't edit template of frame. Blend is showing al edit template menu items disabled. But If I put frame inside layout root grid in normal user control then everything is ok.. like this
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ShellFrame="clr-namespace:Silverlight.Controls;assembly=Silverlight.Controls"
mc:Ignorable="d"
x:Class="Adresar.Test"
d:DesignWidth="640" d:DesignHeight="480">
<Grid x:Name="LayoutRoot">
<ShellFrame:Frame Content="Frame" HorizontalAlignment="Left" Margin="72,136,0,0" VerticalAlignment="Top"/>
</Grid>
Does enybody knows why this is happening? Thank you!
Changing your Frame control to be based on UserControl instead of ContentControl should fix the behavior you're seeing in Blend. I'm not sure how you're using your control, but if you can't utilize a UserControl you might want to include some context.

Resources