Can't use InkCanvas in SilverLight - c#

I am trying to create my first program in SilverLight. But I can't use the InkCanvas.
Simply, I just:
Create a new project.
Choose SilverLight Application (Framework 4.5)
UnCheck "Host the silverlight application in a website..."
SilverLight version 5
"WCF RIA Services" unchecked
Click on ToolBox > Choose Items > Select InkCanvas from SilverLight components
Add InkCanvas to the form & Change it's background color to black
Click on "Start" (Debug)
But I can't see or use the Canvas.
Here is the XAML:
<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:Workspace="clr-namespace:Microsoft.Expression.Prototyping.Workspace;assembly=Microsoft.Expression.Prototyping.Runtime"
x:Class="SilverlightApplication3.MainPage"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<Grid x:Name="LayoutRoot"
Background="White">
<Workspace:InkCanvas HorizontalAlignment="Left"
Height="204"
Margin="36,52,0,0"
VerticalAlignment="Top"
Width="310"
Background="Black" />
</Grid>
</UserControl>
Then I get these 2 errors:
Error 1 Undefined CLR namespace. The 'clr-namespace' URI refers to a
namespace 'Microsoft.Expression.Prototyping.Workspace' that could not
be found. c:\users\xperator\documents\visual studio
2012\Projects\SilverlightApplication3\SilverlightApplication3\MainPage.xaml 6 21 SilverlightApplication3
and
Error 2 The type 'Workspace:InkCanvas' was not found. Verify that you
are not missing an assembly reference and that all referenced
assemblies have been built. c:\users\xperator\documents\visual studio
2012\Projects\SilverlightApplication3\SilverlightApplication3\MainPage.xaml 12 10 SilverlightApplication3
As the error says, there is no Workspace in the Prototyping namespace. I can see in the Solution explorer, there is only 2 References related to the InkCanvas:
Microsoft.Expression.Prototyping.Interactivity
microsoft.expression.prototyping.runtime
Tried to add the "Workspace" from the "Add Reference" but couldn't find it.
UPDATE :
I think actually the InkCanvas is not official ported to silverlight yet. Tried to do the same steps on a fresh pc, and I just noticed InkCanvas wasn't there in the first place. Maybe something related to Blend added the prototype control in my own PC. Still it doesn't work :(
I am open to any suggestion for alternatives to InkCanvas.

Related

"DataContext is not set" message on main window

I'm getting the XLS1106 "DataContext is not set" message on my main window XAML in Visual Studio. As far as I can tell, I haven't used anything related to that and nothing is broken. I would just supress the message, but I'm not sure why it's there.
Here is my whole XAML:
<Window x:Name="MyWindow" x:Class="Whiteboard.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:Whiteboard"
mc:Ignorable="d"
Title="Untitled - CFWhiteboard" Height="450" Width="800" MouseDown="WindowMouseDown" MouseMove="WindowMouseMove" KeyDown="WindowKeyDown" KeyUp="WindowKeyUp" Icon="icons8-interactive-whiteboard-100.png" Loaded="WindowLoaded" Closing="WindowClosing">
<Window.Resources>
<ResourceDictionary>
<FrameworkElement x:Key="CursorRectangle" Cursor="Resources/Cursors/rectangle.cur"/>
<FrameworkElement x:Key="CursorSquare" Cursor="Resources/Cursors/lockrect.cur"/>
<FrameworkElement x:Key="CursorEllipse" Cursor="Resources/Cursors/ellipse.cur"/>
<FrameworkElement x:Key="CursorCircle" Cursor="Resources/Cursors/lockellipse.cur"/>
</ResourceDictionary>
</Window.Resources>
<Canvas x:Name="MainCanvas"/>
</Window>
The message is a false positive. The fix for the problem is available in the latest preview version of Visual Studio:
Microsoft Solution - Bhavya Udayashankar [MSFT] Closed - Fixed ···
A fix for this issue has been released! Install the most recent preview release from https://visualstudio.microsoft.com/downloads/. Thank you for providing valuable feedback which has helped improve the product.
See issue "XLS1106 on virgin C# WPF .Net application" on the Visual Studio Developer Community site.
In the simplest applications without any data bindings set up, there is no need for a data context to be set, and the warning given can be safely ignored.
Note that you should NOT follow the advice of the comment above telling you to add DataContext = this; to the window's constructor for real-world applications. Write a proper view model object type, and create an instance of that to set as your DataContext reference.

Navigation Failed. Cannot Locate Resource for ModernTab WPF

I am using ModernUI in my application. In the code below, I have a link "General" in ModernTab which is inside a window PriceSettingsView in a project PriceSettingsUI. When I run this application the PriceSettingsView window is shown and the link "General" is also working fine, but when I use PriceSettingsView in another project (calling from menu click event), the PriceSettingView window is showing up but the "General" link displays the following error message:
Navigation Failed. Cannot locate resource
Can someone please suggest why it is not working when calling the view from another project? Is something wrong with the source attribute when calling the view from another project?
<mui:ModernWindow x:Class="PriceSettingsUI.PriceSettingsView"
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:mui="http://firstfloorsoftware.com/ModernUI"
mc:Ignorable="d"
Style="{StaticResource EmptyWindow}" Title="PriceSettingsView" Height="700" Width="900">
<Border Margin="0,5,0,0" BorderBrush="{StaticResource Accent}" BorderThickness="1">
<mui:ModernTab>
<mui:ModernTab.Links>
<mui:Link DisplayName="General" Source="/Views/GeneralSettings.xaml"/>
</mui:ModernTab.Links>
</mui:ModernTab>
</Border>
</mui:ModernWindow>
Error Message:
Please let me if anyone needs additional information.
But, when I use "PriceSettingsView" in another project (calling from menu click event) PriceSettingView window is showing up but link "General" giving error message as "Navigation Failed. Cannot locate resource".
You provide a URI for GeneralSettings that is relative to the current project. In the original project A, the Views folder exists and contains the GeneralSettings view, but when you use PriceSettingsView in another project B, there neither the folder nor the view are present and therefore the view cannot be resolved.
You have to specify the URI to GeneralSettings relative to the assembly that contains it and reference the corresponding project. Specify the referenced assembly in the URI, for example:
<mui:Link DisplayName="General" Source="/PriceSettingsUI;component/Views/GeneralSettings.xaml"/>

On Windows 10 (1803), all applications lost touch or stylus if a WPF transparent window covers on them

If I create a new WPF application with a simple empty window like the code shown below, I find that all applications which are covered by the WPF app lost touch or stylus reaction. This can only be reproduced when Windows 10 is upgraded to 1803 (10.0.17134.0).
<Window x:Class="TheWPFCoveringWindow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None" WindowState="Maximized"
AllowsTransparency="True" Background="Transparent"
Topmost="True">
<Button Content="Test" Width="200" Height="100" />
</Window>
I wrote another WPF application to find out what happened. So I add a StylusDown event to the Window like the code shown below:
// This code is in another WPF application.
private void OnStylusDown(object sender, StylusDownEventArgs e)
{
// Set a breakpoint here.
}
But the breakpoint never reached until I closed the transparent WPF window which is on top.
I pushed the very simple code to GitHub: dotnet-campus/TouchIssueOnWindows10.0.17134. Cloning it might help a little.
Why does this happen and how to solve it? Any reply is appreciated.
Updated
Microsoft has fixed this issue in .NET Framework August 2018 Preview of Quality Rollup.
August 30, 2018—KB4346783 (OS Build 17134.254)
Addresses an issue where touch and mouse events were handled differently in Windows Presentation Foundation (WPF) applications that have a transparent overlay window.
Original
After a whole week's debugging, I finally find out the solution.
Just add a ResizeMode="NoResize" property for the Window as the code shown below:
<Window x:Class="TheWPFCoveringWindow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None" WindowState="Maximized"
AllowsTransparency="True" ResizeMode="NoResize"
Background="Transparent" Topmost="True">
<Button Content="Test" Width="200" Height="100" />
</Window>
#lindexi has posted this issue and this solution into his post. If you want more information about this issue, read win10 17025 touch bug - lindexi for more details. (This post is written in multiple languages, so you'll miss nothing even if you ignore the unknown characters.)
Actually, I still can't figure out why this property helps.
Could anyone explain the reason for this issue?

How to get started with Microsofts RibbonControlsLibrary?

I'm new to WPF programming and decided to give it a shot by trying out some ribbon control libraries.
The library that looks best for now is the Microsoft RibbonControlsLibrary. You can get it on the ribbon licensing page.
So far I've started a new project, added the control to the windows, but them I'm stuck: This is the code so far:
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="808" xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit" xmlns:my1="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary" WindowStyle="SingleBorderWindow">
<Grid>
<my1:Ribbon HorizontalAlignment="Left" Name="ribbon1" VerticalAlignment="Top" Height="165" Width="786" ShowQuickAccessToolbarOnTop="False" WindowIconVisibility="Visible" DataContext="{Binding}" Margin="0,-20,0,0">
<my1:Ribbon.ApplicationMenu>
<my1:RibbonApplicationMenu Visibility="Hidden" IsEnabled="True" />
</my1:Ribbon.ApplicationMenu>
<my1:RibbonTab Label="Tab1" Name="rtab1" >
</my1:RibbonTab>
<my1:RibbonTab Label="tab2" Name="rtab2"/>
</my1:Ribbon>
</Grid>
</Window>
Questions:
1) Where can I find samples for this ribbon control? I've tried googling, but came up with nothing useful.
2) How to add items to specific ribbon tabs? I'm lost in all these properties in the property grid. So far I havent found a designer for that purpose.
3) How can I switch the designer to show me what icons/button/... I placed on TabPage2?
(FYI: The fluent ribbon library does not seem to work for me, because I can't get rid of the ApplicationMenu.)
Found a great sample/tutorial:
http://windowsclient.net/downloads/folders/hands-on-labs/entry76491.aspx
The sample provides a manual with explanations and some test projects with step by step instructions to implement the ribbon control.
Though I'm totally new to WPF, I managed to extract necessary classes from the sample to provide a ribon based menu in my program.

Using ICSharpCode.AvalonEdit on .Net 3.5?

I'm trying to use the ICSharpCode.AvalonEdit.TextEditor control from the SharpDevelop 4.0 project in a WPF app that I'm building, but I can't seem to get it to work.
I checked out a copy of the source code from svn://svnmirror.sharpdevelop.net/sharpdevelop/trunk/SharpDevelop/src/Libraries/AvalonEdit at revision 4304. Then, I built the project using Visual Studio 2008 SP1, which succeeded without errors.
I then created a blank new WPF project, added the build DLL to the toolbox and dropped the TextEditor control onto the default empty window, like so:
<Window x:Class="AvalonEditTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit"
Title="Window1" Height="300" Width="300" >
<Grid x:Name="LayoutRoot">
<avalonedit:TextEditor Name="textEditor" />
</Grid>
</Window>
However, when I run the project, the form comes up completely blank. No caret, the mouse cursor stays the default pointer, and the window does not respond to keypresses.
Am I missing something, or is AvalonEdit just a little broken?
[EDIT: I'm starting to think it might be related to my specific setup. I'm running the 64-bit Windows 7 RC. Might that have something to do with it? I've tried building it for x86 only, made no difference.]
Are you sure your namespace declaration is correct?
You can try something like this:
<Window x:Class="Editor.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300"
xmlns:e="clr-namespace:ICSharpCode.AvalonEdit;assembly=ICSharpCode.AvalonEdit">
<Grid>
<e:TextEditor x:Name="Editor" WordWrap="True" Height="200">
</e:TextEditor>
</Grid>
</Window>
I was able to get it to work without any issues.
The AvalonEdit TextEditor is just a view for a TextDocument model.
The problem was that a new AvalonEdit instance didn't start connected to any model instance, so there wasn't anything to edit.
The reason the code from statictype worked was that he didn't use <avalonedit:TextEditor/>, but <avalonedit:TextEditor></avalonedit:TextEditor>. This will assign an empty string to the Text property, which caused the editor to implicitly create a new document.
But this isn't relevant with recent AvalonEdit versions anymore, the editor will now always create a new TextDocument.
This works for me with the latest build
<DockPanel LastChildFill="True">
<avalonedit:TextEditor
HorizontalAlignment="Stretch"
Name="textEditor1"
VerticalAlignment="Stretch" />
</DockPanel>

Categories

Resources