本文整理汇总了C#中DataTemplate类的典型用法代码示例。如果您正苦于以下问题:C# DataTemplate类的具体用法?C# DataTemplate怎么用?C# DataTemplate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataTemplate类属于命名空间,在下文中一共展示了DataTemplate类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:28,代码来源:BindingTests.cs
示例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;
};
}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:31,代码来源:CellTypeList.cs
示例3: ViewPresenter
public ViewPresenter(DataTemplate viewTemplate, DataTemplateSelector viewTemplateSelector) {
ContentTemplate = viewTemplate;
#if !SILVERLIGHT
ContentTemplateSelector = viewTemplateSelector;
#endif
Loaded += ViewPresenter_Loaded;
}
开发者ID:ruisebastiao,项目名称:DevExpress.Mvvm.Free,代码行数:7,代码来源:ViewHelper.cs
示例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;
}
开发者ID:sk8tz,项目名称:DevExpress.Mvvm.Free,代码行数:7,代码来源:IViewLocator.cs
示例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;
}
开发者ID:modulexcite,项目名称:SilverlightToolkit,代码行数:31,代码来源:CultureInfoEditor.cs
示例6: Create
public void Create()
{
var template = new DataTemplate (typeof(SwitchCell));
var content = template.CreateContent();
Assert.That (content, Is.InstanceOf<SwitchCell>());
}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:7,代码来源:SwitchCellTests.cs
示例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 };
});
}
开发者ID:ytn3rd,项目名称:Xamarin.Forms,代码行数:32,代码来源:Bugzilla42277.cs
示例8: CreateContentType
public void CreateContentType()
{
var template = new DataTemplate (typeof (MockBindable));
object obj = template.CreateContent();
Assert.IsNotNull (obj);
Assert.That (obj, Is.InstanceOf<MockBindable>());
}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:8,代码来源:DataTemplateTests.cs
示例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));
}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:8,代码来源:SwitchCellTests.cs
示例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"));
}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:8,代码来源:SwitchCellTests.cs
示例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;
}
开发者ID:yan122725529,项目名称:SqlComPare_Mvvm,代码行数:11,代码来源:EmptyEditor.cs
示例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);
}
开发者ID:LINDAIS,项目名称:DevExpress.Mvvm.Free,代码行数:9,代码来源:ViewHelper.cs
示例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"));
}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:9,代码来源:DataTemplateTests.cs
示例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"));
}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:10,代码来源:DataTemplateTests.cs
示例15: PrepareContainerForItem
public void PrepareContainerForItem(object item, DataTemplate template)
{
if (!ContainsValue(ContentTemplateProperty) && !ContainsValue(ContentTemplateSelectorProperty))
{
this.ContentTemplate = template;
isContainerTemplate = true;
}
Content = item;
}
开发者ID:diab0l,项目名称:Granular,代码行数:10,代码来源:ContentPresenter.cs
示例16: DetailsTemplate
public void DetailsTemplate()
{
Type propertyType = typeof(DataTemplate);
bool expectGet = true;
bool expectSet = true;
bool hasSideEffects = true;
DataGridRow control = new DataGridRow();
Assert.IsNotNull(control);
// Verify Dependency Property Property member
FieldInfo fieldInfo = typeof(DataGridRow).GetField("DetailsTemplateProperty", BindingFlags.Static | BindingFlags.Public);
Assert.AreEqual(typeof(DependencyProperty), fieldInfo.FieldType, "DataGridRow.DetailsTemplateProperty not expected type 'DependencyProperty'.");
// Verify Dependency Property Property's value type
DependencyProperty property = fieldInfo.GetValue(null) as DependencyProperty;
Assert.IsNotNull(property);
//
// Verify Dependency Property CLR property member
PropertyInfo propertyInfo = typeof(DataGridRow).GetProperty("DetailsTemplate", BindingFlags.Instance | BindingFlags.Public);
Assert.IsNotNull(propertyInfo, "Expected CLR property DataGridRow.DetailsTemplate does not exist.");
Assert.AreEqual(propertyType, propertyInfo.PropertyType, "DataGridRow.DetailsTemplate not expected type 'DataTemplate'.");
// Verify getter/setter access
Assert.AreEqual(expectGet, propertyInfo.CanRead, "Unexpected value for propertyInfo.CanRead.");
Assert.AreEqual(expectSet, propertyInfo.CanWrite, "Unexpected value for propertyInfo.CanWrite.");
// Verify that we set what we get
if (expectSet) // if expectSet == false, this block can be removed
{
DataTemplate template = new DataTemplate();
control.DetailsTemplate = template;
Assert.AreEqual(template, control.DetailsTemplate);
}
// Verify Dependency Property callback
if (hasSideEffects)
{
MethodInfo methodInfo = typeof(DataGridRow).GetMethod("OnDetailsTemplatePropertyChanged", BindingFlags.Static | BindingFlags.NonPublic);
Assert.IsNotNull(methodInfo, "Expected DataGridRow.DetailsTemplate to have static, non-public side-effect callback 'OnDetailsTemplatePropertyChanged'.");
//
}
else
{
MethodInfo methodInfo = typeof(DataGridRow).GetMethod("OnDetailsTemplatePropertyChanged", BindingFlags.Static | BindingFlags.NonPublic);
Assert.IsNull(methodInfo, "Expected DataGridRow.DetailsTemplate NOT to have static side-effect callback 'OnDetailsTemplatePropertyChanged'.");
}
}
开发者ID:dfr0,项目名称:moon,代码行数:55,代码来源:DetailsTemplate.cs
示例17: SetBindingOverridesValue
public void SetBindingOverridesValue()
{
var template = new DataTemplate (typeof (MockBindable));
template.SetValue (MockBindable.TextProperty, "value");
template.SetBinding (MockBindable.TextProperty, new Binding ("."));
MockBindable bindable = (MockBindable) template.CreateContent();
Assume.That (bindable.GetValue (MockBindable.TextProperty), Is.EqualTo (bindable.BindingContext));
bindable.BindingContext = "binding";
Assert.That (bindable.GetValue (MockBindable.TextProperty), Is.EqualTo ("binding"));
}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:12,代码来源:DataTemplateTests.cs
示例18: CreateViewTemplate
public static DataTemplate CreateViewTemplate(this IViewLocator viewLocator, Type viewType) {
Verify(viewLocator);
if(viewType == null) throw new ArgumentNullException("viewType");
DataTemplate res = null;
try {
res = new DataTemplate() { VisualTree = new FrameworkElementFactory(viewType) };
res.Seal();
} catch {
res = CreateFallbackViewTemplate(GetErrorMessage_CannotCreateDataTemplateFromViewType(viewType.Name));
}
return res;
}
开发者ID:LINDAIS,项目名称:DevExpress.Mvvm.Free,代码行数:12,代码来源:IViewLocator.cs
示例19: TextBoxEditor
/// <summary>
/// Default constructor builds the default TextBox inline editor template.
/// </summary>
public TextBoxEditor()
{
FrameworkElementFactory textBox = new FrameworkElementFactory(typeof(TextBox));
Binding binding = new Binding();
binding.Path = new PropertyPath("Value");
binding.Mode = BindingMode.TwoWay;
textBox.SetBinding(TextBox.TextProperty, binding);
DataTemplate dt = new DataTemplate();
dt.VisualTree = textBox;
InlineEditorTemplate = dt;
}
开发者ID:shijiaxing,项目名称:SilverlightToolkit,代码行数:16,代码来源:TextBoxEditor.cs
示例20: EmptyTextCell
public void EmptyTextCell (bool useCompiledXaml)
{
var layout = new DataTemplate (useCompiledXaml);
var cell0 = layout.emptyTextCell.ItemTemplate.CreateContent ();
Assert.NotNull (cell0);
Assert.That (cell0, Is.TypeOf<TextCell> ());
var cell1 = layout.emptyTextCell.ItemTemplate.CreateContent ();
Assert.NotNull (cell1);
Assert.That (cell1, Is.TypeOf<TextCell> ());
Assert.AreNotSame (cell0, cell1);
}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:14,代码来源:DataTemplate.xaml.cs
注:本文中的DataTemplate类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论