美文网首页
常用代码(待更新)

常用代码(待更新)

作者: ColeX | 来源:发表于2018-10-05 14:56 被阅读16次

    Model

    public class Model : INotifyPropertyChanged
    {
        private string content;
        public string Content {
    
            get
            {
                return content;
            }
            set {
                content = value;
                NotifyPropertyChanged();
            }
        }
    
        public event PropertyChangedEventHandler PropertyChanged;
    
        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    

    Custom Renderer

    [assembly: ExportRenderer(typeof(TableView), typeof(CustomListRenderer))]
    namespace PPPPCL.iOS
    {
        class CustomListRenderer  :TableViewRenderer
        {
           protected override void OnElementChanged(ElementChangedEventArgs<TableView> e)
            {
                base.OnElementChanged(e);
                if(Control != null)
                {
                
                }
            }
        }
    }
    

    BindableStackLayout

    public class BindableStackLayout : StackLayout
    {
        public IEnumerable ItemsSource
        {
            get { return (IEnumerable)GetValue(ItemsSourceProperty); }
            set { SetValue(ItemsSourceProperty, value); }
        }
        public static readonly BindableProperty ItemsSourceProperty =
            BindableProperty.Create(nameof(ItemsSource), typeof(IEnumerable), typeof(BindableStackLayout),
                                    propertyChanged: (bindable, oldValue, newValue) => ((BindableStackLayout)bindable).PopulateItems());
    
        public DataTemplate ItemDataTemplate
        {
            get { return (DataTemplate)GetValue(ItemDataTemplateProperty); }
            set { SetValue(ItemDataTemplateProperty, value); }
        }
        public static readonly BindableProperty ItemDataTemplateProperty =
            BindableProperty.Create(nameof(ItemDataTemplate), typeof(DataTemplate), typeof(BindableStackLayout));
    
        void PopulateItems()
        {
            if (ItemsSource == null) return;
            foreach (var item in ItemsSource)
            {
                var itemTemplate = ItemDataTemplate.CreateContent() as Xamarin.Forms.View;
                itemTemplate.BindingContext = item;
                Children.Add(itemTemplate);
            }
        }
    }
    

    查看已有的fontName

    foreach (var familyNames in UIFont.FamilyNames.OrderBy(c => c).ToList())
            {
                Console.WriteLine(" * " + familyNames);
                foreach (var familyName in UIFont.FontNamesForFamilyName(familyNames).OrderBy(c => c).ToList())
                {
                    Console.WriteLine(" *-- " + familyName);
                }
            }
    

    OnPlatform 用法

    代码

     Icon = (Device.RuntimePlatform == Device.iOS) ? "tab_about.png" : null;
    

    xaml

             <ContentPage.Padding>
        <OnPlatform x:TypeArguments="Thickness">
            <OnPlatform.Platforms>
                <On Platform="iOS" Value="0, 20, 0, 0" />
                <On Platform="Android" Value="0, 0, 0, 0" />
                <On Platform="UWP" Value="0, 0, 0, 0" />
            </OnPlatform.Platforms>
        </OnPlatform>
       </ContentPage.Padding>
    

    相关文章

      网友评论

          本文标题:常用代码(待更新)

          本文链接:https://www.haomeiwen.com/subject/oejqaftx.html