Need sample app using wpf, prism 6, Unity and implements a module - wpf

All samples found either address earlier version of prism or don't currently work. I am using Visual Studio 2015. I am specifically looking for an example of using ViewmodelLocator.AutoWireViewModel

There is an offical example available at GitHub: https://github.com/PrismLibrary/Prism-Samples-Wpf/tree/master/HelloWorld
This sample uses Unity and ViewA uses the view model locatator to create an instance of ViewAViewModel: https://github.com/PrismLibrary/Prism-Samples-Wpf/blob/master/HelloWorld/Modules/ModuleA/Views/ViewA.xaml
<UserControl x:Class="ModuleA.Views.ViewA"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True">
<Grid>
<TextBlock Text="{Binding Title}" Foreground="Green" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Calibri" FontSize="24" FontWeight="Bold"></TextBlock>
</Grid>
</UserControl>

Related

PlaceholderText is not accessible XAML

I am new to XAML and WPF.
I am trying to add a placeholder to my textbox but I got this error: "The property 'PlaceholderText' was not found in type 'TextBox'" and "The member "PlaceholderText" is not recognized or is not accessible".
When I tried to type PlaceholderText, it didn't even show up in the auto-complete drop down list. "Header" has the problem.
I am using VS 2015 community and .NET Framework 4.5.2
Below is my code which I got it from https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.textbox#Examples
<Window x:Class="QuickGarbageSort.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:local="clr-namespace:MyTestApp"
mc:Ignorable="d"
Title="MyTestApp" Height="550" Width="800">
<StackPanel>
<TextBlock Text="What's your name?"/>
<StackPanel Orientation="Horizontal" Margin="0,20,0,20">
<TextBox x:Name="nameInput"
Header="Enter your name:" PlaceholderText="Name"
Width="300" HorizontalAlignment="Left"/>
<Button Content="Hello button" Click="Button_Click"/>
</StackPanel>
<TextBlock x:Name="greetingOutput"/>
</StackPanel>
The documentation you got the code from is a documentation for Windows.UI.Xaml.Controls.TextBox, this is the textbox control used in Universal Windows Applications. This has a property called PlaceholderText
The WPF one is System.Windows.Controls.TextBox, this is different and doesn't have a PlaceholderText property. In order to have something like the UWP placeholder text in WPF, you have to implement it yourself or use a third party library which offers a control with this functionality.

Why does this Microsoft.VisualStudio.Imaging.CrispImage does not show anything?

I am trying to create a very simple WPF application to experiment this concept of the Visual Studio Image Service and Catalog.
I don't understand why I cannot seem to be able to show any of the known images (using KnownMonikers) both on the WPF designer or when the app runs.
The image is there. It just does not show anything.
Here's the WPF source code (following exactly the steps described in the MSDN link above):
<Window x:Class="ImageCatalogBrowser.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:local="clr-namespace:ImageCatalogBrowser"
xmlns:imaging="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.Imaging"
xmlns:theming="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Imaging"
xmlns:utilities="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Utilities"
xmlns:catalog="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.ImageCatalog"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<utilities:BrushToColorConverter x:Key="BrushToColorConverter"/>
</Window.Resources>
<Grid>
<StackPanel
Background="White"
VerticalAlignment="Center"
theming:ImageThemingUtilities.ImageBackgroundColor="{Binding Background, RelativeSource={RelativeSource Self}, Converter={StaticResource BrushToColorConverter}}">
<Border BorderThickness="1" BorderBrush="Black" Width="33" Height="33">
<imaging:CrispImage
x:Name="crisp"
Visibility="Visible"
Width="32"
Height="32"
Moniker="{x:Static catalog:KnownMonikers.Save}" />
</Border>
</StackPanel>
</Grid>
</Window>
Can anyone help please?
What's your code-behind doing to initialize the ImageLibrary? If the library cannot find the moniker you're requesting, then it won't display the image.
Make sure when initializing the ImageLibrary you give it the path to the ImageCatalog's .imagemanifest file (in the VS install dir).

How to render Window custom Title using XAML?

I have a Windows Forms Application that shows application Name on most application Forms as shown below. For application name 'VScodePrint 2015' I used a bitmap. To support high resolution screens I had to make a number of copies of this image to support different DPI settings.
I have just started redesigning my application using WPF to avoid having to set different images based on the DPI setting without using images.
I have created a WPF window but not sure how to render the application name like the Windows Forms version above.
Can some please show me how to render the application as per Windows Form version using XAML?
System.IO.Path.GetFileName(Assembly.GetEntryAssembly().GetName().Name);
Set a label or whatever control's content equal to that, and you will get the name as you are wanting.
I have managed to create a usercontrol that renders Window title for my windows. I am novice using WPF so may this not be the best XAML but here it is:
<UserControl x:Class="WindowTitle"
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:WpfApplication2"
mc:Ignorable="d" Height="109.986" Width="404.929">
<RowDefinition Height="80"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border BorderBrush="DarkGray" BorderThickness="1" CornerRadius="10,10,0,0 " Background="#FF61238B" Margin="0,0,0,1">
<StackPanel Width="Auto" Height="Auto">
<StackPanel Height="Auto" Margin="0,0,0,0" HorizontalAlignment="Center" >
<Label x:Name="lblYear" Content="2015" FontSize="12" BorderBrush="White" Foreground="White" HorizontalContentAlignment="Right" Padding="0,0,0,0" VerticalAlignment="Bottom" FontFamily="Global User Interface" Margin="0,5,0,0"/>
<Label x:Name="lblProductName" Content="VScodePrint" FontSize="48" BorderBrush="White" Foreground="White" HorizontalContentAlignment="Right" Padding="0,0,0,0" VerticalAlignment="Top" FontFamily="Global User Interface" Margin="0,-5,0,0"/>
</StackPanel>
</StackPanel>
</Border>
<Label x:Name="lblVersion" Content="Version 14.0.20 Rev 1510" Grid.Row="1" VerticalAlignment="Center" Height="37" HorizontalContentAlignment="Center" Margin="0,0,0.429,0" FontFamily="Segoe UI Semibold">
<Label.Background>
<SolidColorBrush Color="#FFDBCBE3"/>
</Label.Background>
</Label>
Below is the above Window Title usercontrol in action:

Binding example

I have been trying for weeks to find a decent article that explains WPF Binding simply and with a working example that actually explains what is happening. Yes there are lots of examples out there but lots of those refer to older versions of everything involved.
I am trying to write an application, that is not web based, uses WPF and VB on VS2012.
In this bit of code i am updating a screen field directly, but i want to learn how to update a variable in memory and it update on the screen automatically, how do i get from here to there - In stages with explanations
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Test Bind"
Height="299" Width="500" WindowStartupLocation="CenterScreen">
<DockPanel HorizontalAlignment="Stretch" LastChildFill="False" VerticalAlignment="Stretch">
<DockPanel DockPanel.Dock="Top" Height="64">
<Button Content="Button" Height="64" VerticalAlignment="Top" Width="75" Click="Button_Click" />
<TextBox Height="64" Width="120" Text="TextBox1" x:Name="clickcount" />
<TextBox Height="64" Width="120" x:Name="textBox2" Text="{Binding Test, Mode=Default}" />
</DockPanel>
</DockPanel>
</Window>
Class MainWindow
Public Shared clcount As Integer = 0
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
clcount = clcount + 1
Me.clickcount.Text = clcount.ToString
End Sub
End Class

Error about UserControl not supported in WPF in Expression Blend 2

I've created a test Silverlight 2 app in Visual Studio, just copying the Tim Heuer video, but when I go to open it in Blend I get this error
UserControl is not supported in a Windows Presentation Foundation (WPF) project
This is the XAML code
<UserControl x:Class="MyFirstApp.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel Orientation="Vertical">
<TextBox x:Name="myTextBox" FontSize="60" />
<Button Content="Click Me" FontSize="60" Click="Button_Click" />
</StackPanel>
</Grid>
</UserControl>
Am I missing a reference or something?
You need to install Expression Blend 2.0 SP1.
Please take a look at this thread:
http://social.expression.microsoft.com/Forums/en-US/blend/thread/33030347-c99a-4f41-8be7-089c92e4ab2d

Resources