Browse Source

Fixed XamlDesigner sample

pull/1/head
Daniel Grunwald 15 years ago
parent
commit
cef7bd1a6c
  1. 4
      samples/HtmlSyntaxColorizer/HtmlSyntaxColorizer.csproj
  2. 6
      samples/HtmlSyntaxColorizer/HtmlSyntaxColorizer.sln
  3. 1
      samples/XamlDesigner/App.xaml.cs
  4. 43
      samples/XamlDesigner/DocumentView.xaml
  5. 29
      samples/XamlDesigner/DocumentView.xaml.cs
  6. 132
      samples/XamlDesigner/MainWindow.xaml.cs
  7. 16
      samples/XamlDesigner/XamlDesigner.csproj

4
samples/HtmlSyntaxColorizer/HtmlSyntaxColorizer.csproj

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<ProjectGuid>{6D17428C-A444-4C26-8FE3-976160F41D97}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
<OutputType>Exe</OutputType>
<RootNamespace>HtmlSyntaxColorizer</RootNamespace>
<AssemblyName>HtmlSyntaxColorizer</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>

6
samples/HtmlSyntaxColorizer/HtmlSyntaxColorizer.sln

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
# SharpDevelop 4.0.0.5490
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
# SharpDevelop 4.0.0.6517
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HtmlSyntaxColorizer", "HtmlSyntaxColorizer.csproj", "{6D17428C-A444-4C26-8FE3-976160F41D97}"
EndProject
Global

1
samples/XamlDesigner/App.xaml.cs

@ -18,7 +18,6 @@ namespace ICSharpCode.XamlDesigner @@ -18,7 +18,6 @@ namespace ICSharpCode.XamlDesigner
{
DispatcherUnhandledException += App_DispatcherUnhandledException;
Args = e.Args;
System.Windows.Forms.Application.EnableVisualStyles();
base.OnStartup(e);
}

43
samples/XamlDesigner/DocumentView.xaml

@ -1,23 +1,22 @@ @@ -1,23 +1,22 @@
<UserControl
x:Class="ICSharpCode.XamlDesigner.DocumentView"
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Integration="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:TextEditor="clr-namespace:ICSharpCode.TextEditor;assembly=ICSharpCode.TextEditor"
xmlns:Default="clr-namespace:ICSharpCode.XamlDesigner"
xmlns:DesignerControls="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls;assembly=ICSharpCode.WpfDesign.Designer"
>
<DockPanel>
<DesignerControls:EnumBar Value="{Binding Mode}"
DockPanel.Dock="Bottom"/>
<Grid>
<Integration:WindowsFormsHost Visibility="{Binding InXamlMode, Converter={StaticResource CollapsedWhenFalse}}">
<TextEditor:TextEditorControl x:Name="uxTextEditor" />
</Integration:WindowsFormsHost>
<ContentPresenter Content="{Binding DesignSurface}"
Visibility="{Binding InDesignMode, Converter={StaticResource CollapsedWhenFalse}}"/>
</Grid>
</DockPanel>
<UserControl
x:Class="ICSharpCode.XamlDesigner.DocumentView"
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Default="clr-namespace:ICSharpCode.XamlDesigner"
xmlns:DesignerControls="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls;assembly=ICSharpCode.WpfDesign.Designer"
xmlns:AvalonEdit="http://icsharpcode.net/sharpdevelop/avalonedit"
>
<DockPanel>
<DesignerControls:EnumBar
Value="{Binding Mode}"
DockPanel.Dock="Bottom"/>
<Grid>
<AvalonEdit:TextEditor
x:Name="uxTextEditor"
SyntaxHighlighting="XML"
Visibility="{Binding InXamlMode, Converter={StaticResource CollapsedWhenFalse}}" />
<ContentPresenter Content="{Binding DesignSurface}"
Visibility="{Binding InDesignMode, Converter={StaticResource CollapsedWhenFalse}}"/>
</Grid>
</DockPanel>
</UserControl>

29
samples/XamlDesigner/DocumentView.xaml.cs

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
@ -11,9 +12,10 @@ using System.Windows.Media; @@ -11,9 +12,10 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ICSharpCode.WpfDesign.Designer.Services;
using System.Windows.Threading;
using ICSharpCode.WpfDesign.Designer.Services;
namespace ICSharpCode.XamlDesigner
{
public partial class DocumentView
@ -25,9 +27,21 @@ namespace ICSharpCode.XamlDesigner @@ -25,9 +27,21 @@ namespace ICSharpCode.XamlDesigner
Document = doc;
Shell.Instance.Views[doc] = this;
uxTextEditor.SetHighlighting("XML");
uxTextEditor.DataBindings.Add("Text", doc, "Text", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged);
//uxTextEditor.DataBindings.Add("Text", doc, "Text", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged);
Document.Mode = DocumentMode.Design;
Document.PropertyChanged += new PropertyChangedEventHandler(Document_PropertyChanged);
uxTextEditor.TextChanged += new EventHandler(uxTextEditor_TextChanged);
}
void uxTextEditor_TextChanged(object sender, EventArgs e)
{
Document.Text = uxTextEditor.Text;
}
void Document_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "Text" && Document.Text != uxTextEditor.Text)
uxTextEditor.Text = Document.Text;
}
public Document Document { get; private set; }
@ -35,9 +49,12 @@ namespace ICSharpCode.XamlDesigner @@ -35,9 +49,12 @@ namespace ICSharpCode.XamlDesigner
public void JumpToError(XamlError error)
{
Document.Mode = DocumentMode.Xaml;
Dispatcher.BeginInvoke(new Action(delegate {
uxTextEditor.ActiveTextAreaControl.JumpTo(error.Line - 1, error.Column - 1);
}), DispatcherPriority.Background);
try {
uxTextEditor.ScrollTo(error.Line, error.Column);
uxTextEditor.CaretOffset = uxTextEditor.Document.GetOffset(error.Line, error.Column);
} catch (ArgumentException) {
// invalid line number
}
}
}
}

132
samples/XamlDesigner/MainWindow.xaml.cs

@ -35,7 +35,7 @@ namespace ICSharpCode.XamlDesigner @@ -35,7 +35,7 @@ namespace ICSharpCode.XamlDesigner
AvalonDockWorkaround();
RouteDesignSurfaceCommands();
this.AddCommandHandler(RefreshCommand, Shell.Instance.Refresh, Shell.Instance.CanRefresh);
this.AddCommandHandler(RefreshCommand, Shell.Instance.Refresh, Shell.Instance.CanRefresh);
LoadSettings();
ProcessPaths(App.Args);
@ -46,7 +46,7 @@ namespace ICSharpCode.XamlDesigner @@ -46,7 +46,7 @@ namespace ICSharpCode.XamlDesigner
public static MainWindow Instance;
OpenFileDialog openFileDialog;
SaveFileDialog saveFileDialog;
SaveFileDialog saveFileDialog;
protected override void OnDragEnter(DragEventArgs e)
{
@ -80,48 +80,48 @@ namespace ICSharpCode.XamlDesigner @@ -80,48 +80,48 @@ namespace ICSharpCode.XamlDesigner
Shell.Instance.Open(path);
}
void ProcessDrag(DragEventArgs e)
{
e.Effects = DragDropEffects.None;
e.Handled = true;
foreach (var path in e.Data.Paths()) {
if (path.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase) ||
path.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase)) {
e.Effects = DragDropEffects.Copy;
break;
}
else if (path.EndsWith(".xaml", StringComparison.InvariantCultureIgnoreCase)) {
e.Effects = DragDropEffects.Copy;
break;
}
}
}
void ProcessPaths(IEnumerable<string> paths)
{
foreach (var path in paths) {
if (path.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase) ||
path.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase)) {
Toolbox.Instance.AddAssembly(path);
}
else if (path.EndsWith(".xaml", StringComparison.InvariantCultureIgnoreCase)) {
Shell.Instance.Open(path);
}
}
}
public string AskOpenFileName()
{
if (openFileDialog == null) {
openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Xaml Documents (*.xaml)|*.xaml";
}
if ((bool)openFileDialog.ShowDialog()) {
void ProcessDrag(DragEventArgs e)
{
e.Effects = DragDropEffects.None;
e.Handled = true;
foreach (var path in e.Data.Paths()) {
if (path.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase) ||
path.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase)) {
e.Effects = DragDropEffects.Copy;
break;
}
else if (path.EndsWith(".xaml", StringComparison.InvariantCultureIgnoreCase)) {
e.Effects = DragDropEffects.Copy;
break;
}
}
}
void ProcessPaths(IEnumerable<string> paths)
{
foreach (var path in paths) {
if (path.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase) ||
path.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase)) {
Toolbox.Instance.AddAssembly(path);
}
else if (path.EndsWith(".xaml", StringComparison.InvariantCultureIgnoreCase)) {
Shell.Instance.Open(path);
}
}
}
public string AskOpenFileName()
{
if (openFileDialog == null) {
openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Xaml Documents (*.xaml)|*.xaml";
}
if ((bool)openFileDialog.ShowDialog()) {
return openFileDialog.FileName;
}
}
return null;
}
}
public string AskSaveFileName(string initName)
{
@ -148,17 +148,19 @@ namespace ICSharpCode.XamlDesigner @@ -148,17 +148,19 @@ namespace ICSharpCode.XamlDesigner
Height = r.Height;
}
if (Settings.Default.AvalonDockLayout != null) {
uxDockingManager.RestoreLayout(Settings.Default.AvalonDockLayout.ToStream());
}
uxDockingManager.Loaded += delegate {
if (Settings.Default.AvalonDockLayout != null) {
uxDockingManager.RestoreLayout(Settings.Default.AvalonDockLayout.ToStream());
}
};
}
void SaveSettings()
{
{
Settings.Default.MainWindowState = WindowState;
if (WindowState == WindowState.Normal) {
Settings.Default.MainWindowRect = new Rect(Left, Top, Width, Height);
}
if (WindowState == WindowState.Normal) {
Settings.Default.MainWindowRect = new Rect(Left, Top, Width, Height);
}
var writer = new StringWriter();
uxDockingManager.SaveLayout(writer);
@ -169,21 +171,21 @@ namespace ICSharpCode.XamlDesigner @@ -169,21 +171,21 @@ namespace ICSharpCode.XamlDesigner
#region AvalonDockWorkaround
void AvalonDockWorkaround()
{
uxDocumentPane.Items.KeepSyncronizedWith(Shell.Instance.Documents, d => CreateContentFor(d));
}
DocumentContent CreateContentFor(Document doc)
{
var content = new DocumentContent() {
DataContext = doc,
Content = new DocumentView(doc)
};
content.SetBinding(DocumentContent.TitleProperty, "Title");
return content;
}
#endregion
void AvalonDockWorkaround()
{
uxDocumentPane.Items.KeepSyncronizedWith(Shell.Instance.Documents, d => CreateContentFor(d));
}
DocumentContent CreateContentFor(Document doc)
{
var content = new DocumentContent() {
DataContext = doc,
Content = new DocumentView(doc)
};
content.SetBinding(DocumentContent.TitleProperty, "Title");
return content;
}
#endregion
}
}

16
samples/XamlDesigner/XamlDesigner.csproj

@ -45,22 +45,19 @@ @@ -45,22 +45,19 @@
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="AvalonDock, Version=1.1.1231.0, Culture=neutral, PublicKeyToken=85a1e0ada7ec13e4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Libraries\AvalonDock.dll</HintPath>
<Reference Include="AvalonDock">
<HintPath>..\..\bin\AvalonDock.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.AvalonEdit">
<HintPath>..\..\bin\ICSharpCode.AvalonEdit.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.SharpDevelop.Widgets">
<HintPath>..\..\bin\ICSharpCode.SharpDevelop.Widgets.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.TextEditor, Version=3.0.0.3267, Culture=neutral, PublicKeyToken=4d61825e8dd49f1a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\bin\ICSharpCode.TextEditor.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
@ -84,9 +81,6 @@ @@ -84,9 +81,6 @@
<Reference Include="PresentationFramework">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsFormsIntegration">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">

Loading…
Cancel
Save