<TextBlock Text={Localizing Hello}/> <Button Content={Picture New.png}/>
public abstract class MarkupExtension : Binding, IValueConverter { protected MarkupExtension() { Source = Converter = this; } protected MarkupExtension(object source) // set Source to null for using DataContext { Source = source; Converter = this; } protected MarkupExtension(RelativeSource relativeSource) { RelativeSource = relativeSource; Converter = this; } public abstract object Convert(object value, Type targetType, object parameter, CultureInfo culture); public virtual object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } }
public class Localizing : MarkupExtension { public static readonly LocalizingManager Manager = new LocalizingManager(); public Localizing() { Source = Manager; Path = new PropertyPath("Source"); } public string Key { get; set; } public override string ToString() { return Convert(Manager.Source, null, Key, Thread.CurrentThread.CurrentCulture) as string ?? string.Empty; } public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var key = Key; var resourceManager = value as ResourceManager; if (resourceManager == null || string.IsNullOrEmpty(key)) return ":" + key + ":"; var localizedValue = resourceManager.GetString(key); return localizedValue ?? ":" + key + ":"; } } public class LocalizingManager : INotifyPropertyChanged { private ResourceManager _source; public ResourceManager Source { get { return _source; } set { _source = value; PropertyChanged(this, new PropertyChangedEventArgs("Source")); } } public event PropertyChangedEventHandler PropertyChanged = (sender, args) => { }; }
<TextBlock Text="{f:Localizing Key=ApplicationTitle}"/>
<TextBlock Text="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}"/>
this[SharedCommands.Back].CanExecute += (sender, args) => args.CanExecute = TouchIndex > 0; this[SharedCommands.Next].CanExecute += (sender, args) => args.CanExecute = TouchIndex < _toches.Count; this[SharedCommands.Back].Executed += (sender, args) => TouchIndex--; this[SharedCommands.Next].Executed += (sender, args) => TouchIndex++;
<Button Command="{f:Command Key=Back}" Content="{f:Picture Key=/Resources/IconSet/Next.png, Width=32, Height=32}"/> <Button Command="{f:Command Key=Next}" Content="{f:Picture Key=/Resources/IconSet/Next.png, Width=32, Height=32}"/>
public Tool Tool { get { return Get(() => Tool); } set { Set(() => Tool, value); } }
this[() => Background].PropertyChanged += (sender, args) => { Canvas.Children.Clear(); Canvas.Background = Background; _toches.GetRange(0, TouchIndex).ForEach(Canvas.Children.Add); };
Canvas
), which is displayed on the interface, and any touches to it we interpret as brush strokes with a certain brush. For each stroke, a primitive is created, and then it is added to the Canvas.Children
collection. But what if we have a thousand of such strokes, will it affect performance? Yes, it will have a significant effect, so you should at least occasionally do rasterization of the image, that is, clear the Canvas.Children
and place in the Canvas.Background the drawing that turned out at the moment. It looks like this var raster = new WriteableBitmap(Canvas, null); Canvas.Background = new ImageBrush { AlignmentX = AlignmentX.Left, AlignmentY = AlignmentY.Top, Stretch = Stretch.None, ImageSource = raster, }; Canvas.Children.Clear();
List _toches . , _toches Canvas.Children
, _toches
.
: Polyline OpacityMask Canvas. , .
(). , .
, , . , , .
<LinearGradientBrush x:Key="RainbowBrush" StartPoint="0 0" EndPoint="0 0.6"> <LinearGradientBrush.Transform> <ScaleTransform ScaleY="2.8"/> </LinearGradientBrush.Transform> <LinearGradientBrush.GradientStops> <GradientStop Color="#FFFF0000" Offset="0.0"/> <GradientStop Color="#FFFFFF00" Offset="0.1"/> <GradientStop Color="#FF00FF00" Offset="0.2"/> <GradientStop Color="#FF00FFFF" Offset="0.3"/> <GradientStop Color="#FF0000FF" Offset="0.4"/> <GradientStop Color="#FFFF00FF" Offset="0.5"/> <GradientStop Color="#FFFF0000" Offset="0.6"/> </LinearGradientBrush.GradientStops> </LinearGradientBrush>
, – , , . MVVM: . , , , .
!
PS . , , , , . .
collection List _toches . , _toches Canvas.Children
, _toches
.
: Polyline OpacityMask Canvas. , .
(). , .
, , . , , .
<LinearGradientBrush x:Key="RainbowBrush" StartPoint="0 0" EndPoint="0 0.6"> <LinearGradientBrush.Transform> <ScaleTransform ScaleY="2.8"/> </LinearGradientBrush.Transform> <LinearGradientBrush.GradientStops> <GradientStop Color="#FFFF0000" Offset="0.0"/> <GradientStop Color="#FFFFFF00" Offset="0.1"/> <GradientStop Color="#FF00FF00" Offset="0.2"/> <GradientStop Color="#FF00FFFF" Offset="0.3"/> <GradientStop Color="#FF0000FF" Offset="0.4"/> <GradientStop Color="#FFFF00FF" Offset="0.5"/> <GradientStop Color="#FFFF0000" Offset="0.6"/> </LinearGradientBrush.GradientStops> </LinearGradientBrush>
, – , , . MVVM: . , , , .
!
PS . , , , , . .
List _toches . , _toches
Canvas.Children
, _toches
.
: Polyline OpacityMask Canvas. , .
(). , .
, , . , , .
<LinearGradientBrush x:Key="RainbowBrush" StartPoint="0 0" EndPoint="0 0.6"> <LinearGradientBrush.Transform> <ScaleTransform ScaleY="2.8"/> </LinearGradientBrush.Transform> <LinearGradientBrush.GradientStops> <GradientStop Color="#FFFF0000" Offset="0.0"/> <GradientStop Color="#FFFFFF00" Offset="0.1"/> <GradientStop Color="#FF00FF00" Offset="0.2"/> <GradientStop Color="#FF00FFFF" Offset="0.3"/> <GradientStop Color="#FF0000FF" Offset="0.4"/> <GradientStop Color="#FFFF00FF" Offset="0.5"/> <GradientStop Color="#FFFF0000" Offset="0.6"/> </LinearGradientBrush.GradientStops> </LinearGradientBrush>
, – , , . MVVM: . , , , .
!
PS . , , , , . .
List _toches . , _toches
Canvas.Children
, _toches
.
: Polyline OpacityMask Canvas. , .
(). , .
, , . , , .
<LinearGradientBrush x:Key="RainbowBrush" StartPoint="0 0" EndPoint="0 0.6"> <LinearGradientBrush.Transform> <ScaleTransform ScaleY="2.8"/> </LinearGradientBrush.Transform> <LinearGradientBrush.GradientStops> <GradientStop Color="#FFFF0000" Offset="0.0"/> <GradientStop Color="#FFFFFF00" Offset="0.1"/> <GradientStop Color="#FF00FF00" Offset="0.2"/> <GradientStop Color="#FF00FFFF" Offset="0.3"/> <GradientStop Color="#FF0000FF" Offset="0.4"/> <GradientStop Color="#FFFF00FF" Offset="0.5"/> <GradientStop Color="#FFFF0000" Offset="0.6"/> </LinearGradientBrush.GradientStops> </LinearGradientBrush>
, – , , . MVVM: . , , , .
!
PS . , , , , . .
List _toches . , _toches
Canvas.Children
, _toches
.
: Polyline OpacityMask Canvas. , .
(). , .
, , . , , .
<LinearGradientBrush x:Key="RainbowBrush" StartPoint="0 0" EndPoint="0 0.6"> <LinearGradientBrush.Transform> <ScaleTransform ScaleY="2.8"/> </LinearGradientBrush.Transform> <LinearGradientBrush.GradientStops> <GradientStop Color="#FFFF0000" Offset="0.0"/> <GradientStop Color="#FFFFFF00" Offset="0.1"/> <GradientStop Color="#FF00FF00" Offset="0.2"/> <GradientStop Color="#FF00FFFF" Offset="0.3"/> <GradientStop Color="#FF0000FF" Offset="0.4"/> <GradientStop Color="#FFFF00FF" Offset="0.5"/> <GradientStop Color="#FFFF0000" Offset="0.6"/> </LinearGradientBrush.GradientStops> </LinearGradientBrush>
, – , , . MVVM: . , , , .
!
PS . , , , , . .
Source: https://habr.com/ru/post/210778/
All Articles