Browse Source

Fixed XamlDesigner sample

pull/1/head
Daniel Grunwald 16 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. 41
      samples/XamlDesigner/DocumentView.xaml
  5. 29
      samples/XamlDesigner/DocumentView.xaml.cs
  6. 128
      samples/XamlDesigner/MainWindow.xaml.cs
  7. 16
      samples/XamlDesigner/XamlDesigner.csproj

4
samples/HtmlSyntaxColorizer/HtmlSyntaxColorizer.csproj

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?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> <PropertyGroup>
<ProjectGuid>{6D17428C-A444-4C26-8FE3-976160F41D97}</ProjectGuid> <ProjectGuid>{6D17428C-A444-4C26-8FE3-976160F41D97}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -7,7 +7,7 @@
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<RootNamespace>HtmlSyntaxColorizer</RootNamespace> <RootNamespace>HtmlSyntaxColorizer</RootNamespace>
<AssemblyName>HtmlSyntaxColorizer</AssemblyName> <AssemblyName>HtmlSyntaxColorizer</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath> <OutputPath>bin\Debug\</OutputPath>

6
samples/HtmlSyntaxColorizer/HtmlSyntaxColorizer.sln

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

1
samples/XamlDesigner/App.xaml.cs

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

41
samples/XamlDesigner/DocumentView.xaml

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

29
samples/XamlDesigner/DocumentView.xaml.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Windows; using System.Windows;
@ -11,9 +12,10 @@ using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Navigation; using System.Windows.Navigation;
using System.Windows.Shapes; using System.Windows.Shapes;
using ICSharpCode.WpfDesign.Designer.Services;
using System.Windows.Threading; using System.Windows.Threading;
using ICSharpCode.WpfDesign.Designer.Services;
namespace ICSharpCode.XamlDesigner namespace ICSharpCode.XamlDesigner
{ {
public partial class DocumentView public partial class DocumentView
@ -25,9 +27,21 @@ namespace ICSharpCode.XamlDesigner
Document = doc; Document = doc;
Shell.Instance.Views[doc] = this; 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.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; } public Document Document { get; private set; }
@ -35,9 +49,12 @@ namespace ICSharpCode.XamlDesigner
public void JumpToError(XamlError error) public void JumpToError(XamlError error)
{ {
Document.Mode = DocumentMode.Xaml; Document.Mode = DocumentMode.Xaml;
Dispatcher.BeginInvoke(new Action(delegate { try {
uxTextEditor.ActiveTextAreaControl.JumpTo(error.Line - 1, error.Column - 1); uxTextEditor.ScrollTo(error.Line, error.Column);
}), DispatcherPriority.Background); uxTextEditor.CaretOffset = uxTextEditor.Document.GetOffset(error.Line, error.Column);
} catch (ArgumentException) {
// invalid line number
}
} }
} }
} }

128
samples/XamlDesigner/MainWindow.xaml.cs

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

16
samples/XamlDesigner/XamlDesigner.csproj

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

Loading…
Cancel
Save