本文整理汇总了C#中DataTemplate类的典型用法代码示例。如果您正苦于以下问题:C# DataTemplate类的具体用法?C# DataTemplate怎么用?C# DataTemplate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataTemplate类属于命名空间,在下文中一共展示了DataTemplate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RecursiveSettingInSystem
public void RecursiveSettingInSystem ()
{
var tempObjects = new[] {
new {Name = "Test1"},
new {Name = "Test2"}
};
var template = new DataTemplate (typeof (BindableViewCell)) {
Bindings = { {BindableViewCell.NameProperty, new Binding ("Name")} }
};
var cell1 = (Cell)template.CreateContent ();
cell1.BindingContext = tempObjects[0];
cell1.Parent = new ListView ();
var cell2 = (Cell)template.CreateContent ();
cell2.BindingContext = tempObjects[1];
cell2.Parent = new ListView ();
var viewCell1 = (BindableViewCell) cell1;
var viewCell2 = (BindableViewCell) cell2;
Assert.AreEqual ("Test1", viewCell1.Name);
Assert.AreEqual ("Test2", viewCell2.Name);
Assert.AreEqual ("Test1", viewCell1.NameLabel.Text);
Assert.AreEqual ("Test2", viewCell2.NameLabel.Text);
}
示例2: CellTypeList
// TODO Add gallerys for ViewCell, ListView and TableView
public CellTypeList ()
{
var itemList = new List<CellNavigation> {
new CellNavigation ("TextCell List", new TextCellListPage ()),
new CellNavigation ("TextCell Table", new TextCellTablePage ()),
new CellNavigation ("ImageCell List", new ImageCellListPage ()),
new CellNavigation ("ImageCell Url List", new UrlImageCellListPage()),
new CellNavigation ("ImageCell Table", new ImageCellTablePage ()),
new CellNavigation ("SwitchCell List", new SwitchCellListPage ()),
new CellNavigation ("SwitchCell Table", new SwitchCellTablePage ()),
new CellNavigation ("EntryCell List", new EntryCellListPage ()),
new CellNavigation ("EntryCell Table", new EntryCellTablePage ()),
new CellNavigation ("ViewCell Image url table", new UrlImageViewCellListPage())
};
ItemsSource = itemList;
var template = new DataTemplate (typeof (TextCell));
template.SetBinding (TextCell.TextProperty, new Binding ("CellType"));
ItemTemplate = template;
ItemSelected += (s, e) => {
if (SelectedItem == null)
return;
var cellNav = (CellNavigation) e.SelectedItem;
Navigation.PushAsync (cellNav.Page);
SelectedItem = null;
};
}
示例3: ViewPresenter
public ViewPresenter(DataTemplate viewTemplate, DataTemplateSelector viewTemplateSelector) {
ContentTemplate = viewTemplate;
#if !SILVERLIGHT
ContentTemplateSelector = viewTemplateSelector;
#endif
Loaded += ViewPresenter_Loaded;
}
示例4: CreateFallbackViewTemplate
internal static DataTemplate CreateFallbackViewTemplate(string errorText) {
var factory = new FrameworkElementFactory(typeof(FallbackView));
factory.SetValue(FallbackView.TextProperty, errorText);
var res = new DataTemplate() { VisualTree = factory };
res.Seal();
return res;
}
示例5: CultureInfoEditor
/// <summary>
/// Default constructor builds a ComboBox inline editor template.
/// </summary>
public CultureInfoEditor()
{
// not using databinding here because Silverlight does not support
// the WPF CultureConverter that is used by Blend.
FrameworkElementFactory comboBox = new FrameworkElementFactory(typeof(ComboBox));
comboBox.AddHandler(
ComboBox.LoadedEvent,
new RoutedEventHandler(
(sender, e) =>
{
_owner = (ComboBox)sender;
_owner.SelectionChanged += EditorSelectionChanged;
INotifyPropertyChanged data = _owner.DataContext as INotifyPropertyChanged;
if (data != null)
{
data.PropertyChanged += DatacontextPropertyChanged;
}
_owner.DataContextChanged += CultureDatacontextChanged;
}));
comboBox.SetValue(ComboBox.IsEditableProperty, false);
comboBox.SetValue(ComboBox.DisplayMemberPathProperty, "DisplayName");
comboBox.SetValue(ComboBox.ItemsSourceProperty, CultureInfo.GetCultures(CultureTypes.SpecificCultures));
DataTemplate dt = new DataTemplate();
dt.VisualTree = comboBox;
InlineEditorTemplate = dt;
}
示例6: Create
public void Create()
{
var template = new DataTemplate (typeof(SwitchCell));
var content = template.CreateContent();
Assert.That (content, Is.InstanceOf<SwitchCell>());
}
示例7: MyDataTemplateSelector
public MyDataTemplateSelector()
{
_1Template = new DataTemplate(() =>
{
return new TextCell { Text = Success1 };
});
_2Template = new DataTemplate(() =>
{
return new TextCell { Text = Success2 };
});
_3Template = new DataTemplate(() =>
{
return new TextCell { Text = Success3 };
});
_4Template = new DataTemplate(() =>
{
return new TextCell { Text = Success4 };
});
_5Template = new DataTemplate(() =>
{
return new TextCell { Text = Success5 };
});
_6Template = new DataTemplate(() =>
{
return new TextCell { Text = Success6 };
});
}
示例8: CreateContentType
public void CreateContentType()
{
var template = new DataTemplate (typeof (MockBindable));
object obj = template.CreateContent();
Assert.IsNotNull (obj);
Assert.That (obj, Is.InstanceOf<MockBindable>());
}
示例9: On
public void On()
{
var template = new DataTemplate (typeof (SwitchCell));
template.SetValue (SwitchCell.OnProperty, true);
SwitchCell cell = (SwitchCell)template.CreateContent();
Assert.That (cell.On, Is.EqualTo (true));
}
示例10: Text
public void Text()
{
var template = new DataTemplate (typeof (SwitchCell));
template.SetValue (SwitchCell.TextProperty, "text");
SwitchCell cell = (SwitchCell)template.CreateContent();
Assert.That (cell.Text, Is.EqualTo ("text"));
}
示例11: EmptyEditor
/// <summary>
/// Default constructor builds the default TextBox inline editor template.
/// </summary>
public EmptyEditor()
{
FrameworkElementFactory textBox = new FrameworkElementFactory(typeof(TextBox));
textBox.SetValue(TextBox.IsReadOnlyProperty, true);
DataTemplate dt = new DataTemplate();
dt.VisualTree = textBox;
InlineEditorTemplate = dt;
}
示例12: CreateView
public static object CreateView(IViewLocator viewLocator, string documentType, DataTemplate viewTemplate = null, DataTemplateSelector viewTemplateSelector = null) {
if(documentType == null && viewTemplate == null & viewTemplateSelector == null)
throw new InvalidOperationException(string.Format("{0}{1}To learn more, see: {2}", Error_CreateViewMissArguments, System.Environment.NewLine, HelpLink_CreateViewMissArguments));
if(viewTemplate != null || viewTemplateSelector != null) {
return new ViewPresenter(viewTemplate, viewTemplateSelector);
}
IViewLocator actualLocator = viewLocator ?? (ViewLocator.Default ?? ViewLocator.Instance);
return actualLocator.ResolveView(documentType);
}
示例13: CreateContentValues
public void CreateContentValues()
{
var template = new DataTemplate (typeof (MockBindable)) {
Values = { { MockBindable.TextProperty, "value" } }
};
MockBindable bindable = (MockBindable)template.CreateContent();
Assert.That (bindable.GetValue (MockBindable.TextProperty), Is.EqualTo ("value"));
}
示例14: CreateContentBindings
public void CreateContentBindings()
{
var template = new DataTemplate (() => new MockBindable()) {
Bindings = { { MockBindable.TextProperty, new Binding (".") } }
};
MockBindable bindable = (MockBindable)template.CreateContent();
bindable.BindingContext = "text";
Assert.That (bindable.GetValue (MockBindable.TextProperty), Is.EqualTo ("text"));
}
示例15: PrepareContainerForItem
public void PrepareContainerForItem(object item, DataTemplate template)
{
if (!ContainsValue(ContentTemplateProperty) && !ContainsValue(ContentTemplateSelectorProperty))
{
this.ContentTemplate = template;
isContainerTemplate = true;
}
Content = item;
}