Skip to content

Commit

Permalink
XAML Designer Sample -> Better Error Display
Browse files Browse the repository at this point in the history
  • Loading branch information
jogibear9988 committed Nov 1, 2014
1 parent a79ea00 commit 42c60c8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
4 changes: 2 additions & 2 deletions samples/XamlDesigner/DocumentView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
<Grid>
<AvalonEdit:TextEditor
x:Name="uxTextEditor"
SyntaxHighlighting="XML"
SyntaxHighlighting="XML" ShowLineNumbers="True"
Visibility="{Binding InXamlMode, Converter={StaticResource CollapsedWhenFalse}}" />
<ContentPresenter Content="{Binding DesignSurface}"
Visibility="{Binding InDesignMode, Converter={StaticResource CollapsedWhenFalse}}"/>
Visibility="{Binding InDesignMode, Converter={StaticResource CollapsedWhenFalse}}"/>
</Grid>
</DockPanel>
</UserControl>
12 changes: 10 additions & 2 deletions samples/XamlDesigner/DocumentView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public DocumentView(Document doc)
InitializeComponent();

Document = doc;
Shell.Instance.Views[doc] = this;
Shell.Instance.Views[doc] = this;

//uxTextEditor.DataBindings.Add("Text", doc, "Text", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged);
Document.Mode = DocumentMode.Design;
Expand All @@ -52,7 +52,15 @@ public void JumpToError(XamlError error)
try {
uxTextEditor.ScrollTo(error.Line, error.Column);
uxTextEditor.CaretOffset = uxTextEditor.Document.GetOffset(error.Line, error.Column);
} catch (ArgumentException) {

int n = 0;
char chr;
while ((chr = uxTextEditor.Document.GetCharAt(uxTextEditor.CaretOffset + n)) != ' ' && chr != '.' && chr != '<' && chr != '>' && chr != '"')
{ n++; }

uxTextEditor.SelectionLength = n;
}
catch (ArgumentException) {
// invalid line number
}
}
Expand Down
29 changes: 18 additions & 11 deletions samples/XamlDesigner/ErrorListView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Services="clr-namespace:ICSharpCode.WpfDesign.Designer.Services;assembly=ICSharpCode.WpfDesign.Designer">
<Control.Resources>
<DataTemplate DataType="{x:Type Services:XamlError}">
<StackPanel Orientation="Horizontal">
<Image Source="Images/Error.png"
Stretch="None"
Margin="2"/>
<TextBlock Text="{Binding Message}"
VerticalAlignment="Center"/>
</StackPanel>
</DataTemplate>
</Control.Resources>
<Control.Resources>
<DataTemplate DataType="{x:Type Services:XamlError}">
<StackPanel Orientation="Horizontal">
<Image Source="Images/Error.png"
Stretch="None"
Margin="2"/>
<TextBlock TextAlignment="Right" Text="{Binding Line}" Width="25"
VerticalAlignment="Center"/>
<TextBlock Text=" / "
VerticalAlignment="Center"/>
<TextBlock Text="{Binding Column}" Width="25"
VerticalAlignment="Center"/>
<TextBlock Text=" - " />
<TextBlock Text="{Binding Message}"
VerticalAlignment="Center"/>
</StackPanel>
</DataTemplate>
</Control.Resources>
</ListBox>

0 comments on commit 42c60c8

Please sign in to comment.