1 / 17

Сергей Пугачёв Microsoft MVP @ spugachev

Silverlight 5 , XAML и связывание данных. Сергей Пугачёв Microsoft MVP @ spugachev. Сделали то , что просили…. XAML и связывание данных. ImplicitDataTemplates RelativeSource Ancestor Bindings Binding In Style Setters Markup Extensions Databinding Debugging

ranae
Download Presentation

Сергей Пугачёв Microsoft MVP @ spugachev

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Silverlight 5, XAML и связывание данных Сергей ПугачёвMicrosoft MVP @spugachev

  2. Сделали то, что просили…

  3. XAML и связывание данных • ImplicitDataTemplates • RelativeSource Ancestor Bindings • Binding In Style Setters • Markup Extensions • DatabindingDebugging • DataContextChangedEvent (Post Beta) • UpdateSourceTrigger(Post Beta)

  4. Implicit Data Templates

  5. Implicit Data Templates • Шаблоны основаны на типе • Учитывается иерархия наследования <ListBoxItemsSource="{BindingVehicles}"/> <Application.Resources> <ResourceDictionary> <!--Default Vehicle DataTemplate--> <DataTemplateDataType="models:Vehicle"> <Image Source="Vehicle.png"/> </DataTemplate> <DataTemplateDataType="models:Car"> <Image Source="Car.png"/> </DataTemplate> <DataTemplateDataType="models:Truck"> <Image Source="Truck.png"/> </DataTemplate> <DataTemplateDataType="models:Motorcycle"> <Image Source="Motorcycle.png"/> </DataTemplate> </ResourceDictionary> </Application.Resources>

  6. Relative Source

  7. Relative Source <DataTemplate x:Key="StateComboBoxDataTemplate"> <StackPanel Orientation="Horizontal"> <TextBlock Text="{BindingStateCode}"Margin="0,0,5,0"/> <TextBlock Text="{BindingStateName}" Visibility="{BindingIsDropDownOpen, RelativeSource={RelativeSourceFindAncestor AncestorType=ComboBox}, Converter={StaticResourceBoolToVisibilityConverter}}"/> </StackPanel>

  8. Markup Extensions

  9. Markup Extensions publicclassMethodInvokeExtension: IMarkupExtension<object> { // Properties Exposed in XAML as Intellisense Love publicStringMethod { get; set; } // Invoked by the XAML Parser @ runtime publicobjectProvideValue(IServiceProviderserviceProvider) { <UserControl x:Class="AppointmentsView" xmlns:MyUtils="clr-namespace:TestApp;assembly=TestApp"> ... <StackPanel x:Name="LayoutRoot"> <ComboBox Name="appointmentsListBox" SelectionChanged="{MyUtils:MethodInvoke Method=OnAppointmentChanged}"

  10. Binding Style Setters

  11. Binding Style Setters • Создайте класс для представления значений • Создайте экземпляр класса в ресурсах • Используйте связывание данных в стилях namespaceMyProject.Styles { publicclassMyAppStyles: INotifyPropertyChanged{ publicBrushForegroundColor{ get{ return _foregroundColor; } set { _foregroundColor = value; NotifyPropertyChanged("ForegroundColor"); <ResourceDictionaryxmlns:stylesNS="clr-namespace:MyProject.Styles"> <stylesNS:MyAppStyles x:Key="MyAppStyles"/> <StyleTargetType="TextBlock"> <Setter Property="Foreground" Value="{BindingForegroundColor, Source={StaticResourceMyAppStyles}}"

  12. Coming Soon post beta DataContextChanged this.DataContextChanged += View_DataContextChanged; … voidView_DataContextChanged(objectsender, DependencyPropertyChangedEventArgs e) { INotifyPropertyChanged customer; customer = e.OldValueasINotifyPropertyChanged; if (customer != null) customer.PropertyChanged -= customer_PropertyChanged; customer = e.NewValueasINotifyPropertyChanged; if (customer != null) customer.PropertyChanged += customer_PropertyChanged; }

  13. Coming Soon post beta UpdateSourceTrigger <TextBox Name="vinTextBox" Text="{BindingSelectedClaim.InsuredVIN, Mode=TwoWay}" UpdateSourceTrigger=PropertyChanged}"

  14. XAML и связывание данных • ImplicitDataTemplates • RelativeSource Ancestor Bindings • Binding In Style Setters • Markup Extensions • DatabindingDebugging • DataContextChangedEvent (Post Beta) • UpdateSourceTrigger(Post Beta)

  15. Silverlight 5, XAML и DataBinding Сергей ПугачёвMicrosoft MVP @spugachev

More Related