{"id":273279,"date":"2016-01-31T21:01:02","date_gmt":"2016-01-31T18:01:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=273279"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=273279","title":{"rendered":"\u0424\u0438\u0448\u043a\u0438 XAML-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430: \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0442\u043d\u044b\u0435 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440\u044b"},"content":{"rendered":"<p>       \u0421\u0442\u0430\u0442\u044c\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443, \u043d\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u043c\u0443 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0443 \u2014 <i>Composite Converter<\/i> [<i>\u0441\u043e\u0441\u0442\u0430\u0432\u043d\u043e\u0439 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440<\/i>].<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/741\/5d8\/8d1\/7415d88d178848f6a1c93df00c75657c.jpg\" alt=\"image\"\/><a name=\"habracut\"><\/a><br \/>  \u0412\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440\u043e\u0432, \u043d\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439 \u0438\u043c\u0435\u044e\u0449\u0438\u0445\u0441\u044f. \u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u0447\u0430\u0441\u0442\u0438 \u0434\u0443\u0431\u043b\u0438\u0440\u0443\u044e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u043c \u043d\u0438\u0436\u0435 \u043e\u0431\u0440\u0430\u0437\u043e\u043c. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 <i>PostConverter<\/i> \u0438 <i>PostConverterParameter<\/i>.<\/p>\n<pre><code class=\"cs\">using System.Windows.Data;  namespace Aero.Converters.Patterns {     public interface ICompositeConverter : IValueConverter     {         IValueConverter PostConverter { get; set; }         object PostConverterParameter { get; set; }     } } <\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">Inline Converter<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">using System; using System.Globalization; using System.Windows.Data; using Aero.Converters.Patterns;  namespace Aero.Converters {     public class InlineConverter : IInlineConverter, ICompositeConverter     {         public IValueConverter PostConverter { get; set; }         public object PostConverterParameter { get; set; }         public event EventHandler&lt;ConverterEventArgs&gt; Converting;         public event EventHandler&lt;ConverterEventArgs&gt; ConvertingBack;          public object Convert(object value, Type targetType, object parameter, CultureInfo culture)         {             var args = new ConverterEventArgs(value, targetType, parameter, culture);             var handler = Converting;             if (handler != null) handler(this, args);             return PostConverter == null                 ? args.ConvertedValue                 : PostConverter.Convert(args.ConvertedValue, targetType, PostConverterParameter, culture);         }          public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)         {             var args = new ConverterEventArgs(value, targetType, parameter, culture);             var handler = ConvertingBack;             if (handler != null) handler(this, args);             return PostConverter == null                 ? args.ConvertedValue                 : PostConverter.ConvertBack(args.ConvertedValue, targetType, PostConverterParameter, culture);         }     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">Switch Converter<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">using System; using System.Globalization; using System.Linq; using System.Windows; using System.Windows.Data; using System.Windows.Markup; using Aero.Converters.Patterns;  namespace Aero.Converters {     [ContentProperty(&quot;Cases&quot;)]     public class SwitchConverter : DependencyObject, ISwitchConverter, ICompositeConverter     {         public static readonly DependencyProperty DefaultProperty = DependencyProperty.Register(             &quot;Default&quot;, typeof(object), typeof(SwitchConverter), new PropertyMetadata(CaseSet.UndefinedObject));          public SwitchConverter()         {             Cases = new CaseSet();         }          public object Default         {             get { return GetValue(DefaultProperty); }             set { SetValue(DefaultProperty, value); }         }          public CaseSet Cases { get; private set; }          public bool TypeMode { get; set; }          public object Convert(object value, Type targetType, object parameter, CultureInfo culture)         {             if (TypeMode) value = value == null ? null : value.GetType();             var pair = Cases.FirstOrDefault(p =&gt; Equals(p.Key, value) || SafeCompareAsStrings(p.Key, value));             var result = pair == null ? Default : pair.Value;             value = result == CaseSet.UndefinedObject ? value : result;             return PostConverter == null                 ? value                 : PostConverter.Convert(value, targetType, PostConverterParameter, culture);         }          public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)         {             if (TypeMode) value = value == null ? null : value.GetType();             var pair = Cases.FirstOrDefault(p =&gt; Equals(p.Value, value) || SafeCompareAsStrings(p.Value, value));             value = pair == null ? Default : pair.Key;             return PostConverter == null                 ? value                 : PostConverter.ConvertBack(value, targetType, PostConverterParameter, culture);         }          private static bool SafeCompareAsStrings(object a, object b)         {             if (a == null && b == null) return true;             if (a == null || b == null) return false;             return string.Compare(a.ToString(), b.ToString(), StringComparison.OrdinalIgnoreCase) == 0;         }          public IValueConverter PostConverter { get; set; }         public object PostConverterParameter { get; set; }     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440\u044b \u0432 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u043e\u0439 \u0434\u043b\u0438\u043d\u044b \u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u043d\u0430 \u0431\u0430\u0437\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445.<\/p>\n<pre><code class=\"xml\">&lt;Grid.Resources&gt;     &lt;BooleanConverter x:Key=&quot;YesNoConverter&quot; OnTrue=&quot;Yes&quot; OnFalse=&quot;No&quot;\/&gt;          &lt;SwitchConverter x:Key=&quot;CompositeSwitchConverter&quot; PostConverter=&quot;{StaticResource YesNoConverter}&quot;&gt;         &lt;Case Key=&quot;0&quot; Value=&quot;False&quot;\/&gt;         &lt;Case Key=&quot;1&quot; Value=&quot;True&quot;\/&gt;     &lt;\/SwitchConverter&gt; &lt;\/Grid.Resources&gt;  &lt;TextBlock Text=&quot;{Binding Number, Converter={StaticResource CompositeSwitchConverter}}&quot;\/&gt;  Number == 1 =&gt; out: Yes Number == 0 =&gt; out: No <\/code><\/pre>\n<p>  \u0413\u0435\u043d\u0438\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u043e! \u041f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u0441\u044c \u043d\u0430 \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u0435!<br \/>  \u0416\u0438\u0432\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 <i><a href=\"http:\/\/makeloft.by\/ru\/tools\">Aero Framework<\/a><\/i>.<\/p>\n<p>  \u0421\u043f\u0430\u0441\u0438\u0431\u043e!<\/p>\n<p>  P.S. <a href=\"https:\/\/habrahabr.ru\/post\/276185\/\">\u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043e \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440\u0430\u0445<\/a>               <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/276273\/\"> https:\/\/habrahabr.ru\/post\/276273\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u0421\u0442\u0430\u0442\u044c\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443, \u043d\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u043c\u0443 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0443 \u2014 <i>Composite Converter<\/i> [<i>\u0441\u043e\u0441\u0442\u0430\u0432\u043d\u043e\u0439 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440<\/i>].<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/741\/5d8\/8d1\/7415d88d178848f6a1c93df00c75657c.jpg\" alt=\"image\"\/><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-273279","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/273279","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=273279"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/273279\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=273279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=273279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=273279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}