binding

Binding UserControl in XAML

和自甴很熟 提交于 2019-12-13 06:27:51
问题 I am trying to bind a userControl that I create in a class as property. I couldnt figure out how to show it in XAML. Example: public class MainWindowViewModel : ViewModelBase { public UserControl myUserControl { get; set; }; public MainWindowViewModel() : base() { _myUserControl = new WelcomePageView()); } } In XAML: <Window c:Class=".." . . . /> <???? {Binding myUserControl}> </Window> 回答1: Try <ContentControl Content="{Binding your_usercontrol}" /> 来源: https://stackoverflow.com/questions

Insert DateTime format in combobox

无人久伴 提交于 2019-12-13 05:46:20
问题 I've Harvest_Base class where all DateTime formats are shown; class Harvest_Base { public static DateTime storeTime(String date) { DateTime returnValue = new DateTime(); if (date == "") return returnValue; //Time or Date Component Does not Exist string[] formats= {"M/d/yyyy h:mm:ss tt", "M/d/yyyy h:mm tt", "MM/dd/yyyy hh:mm:ss", "M/d/yyyy h:mm:ss", "M/d/yyyy hh:mm tt", "M/d/yyyy hh tt", "M/d/yyyy h:mm", "M/d/yyyy h:mm", "MM/dd/yyyy hh:mm", "M/dd/yyyy hh:mm", "h:mm tt","hh:mm tt","HH:mm:ss","H

How to bind an enumerator or variable to a DataGridComboBox in DataGrid in WPF?

亡梦爱人 提交于 2019-12-13 05:43:47
问题 I want to put the contents of an enumerator, or some array of strings or a specific DataTable as the items of a DatagridComboBox, so how i can bind the enumerator or the array of strings or a DataTable contents to a DataGridComboBox? For example, i have a Datatable i will load to a DataGrid and will bind the records to customized columns, and depending on value of the cell (from the Datatable) when the column (in the DataGrid) is a DataGridComboBox it will auto-select the corresponding item

Binding the position and size of a UserControl inside a Canvas in WPF

一个人想着一个人 提交于 2019-12-13 05:09:36
问题 We need to dynamically create (i.e. during runtime, via code-behind) UserControls and position them on a Canvas. We want to bind the position (Canvas.Left and Canvas.Top) and width of those sizable (!) and draggable (!) UserControls to a ObservableCollection<>. That measn when the user drags or resizes the control, the datasource gets automatically updated. How would we achieve this if the Usercontrol is contained in a DataTemplate which in turn is used by a ListBox whose DataContext is set

Binding between Resources.DataTemplate and ListBox.DataTemplate - Windows Phone

喜夏-厌秋 提交于 2019-12-13 05:08:40
问题 I'm having problems to do a binding in Windows Phone. Hope you can help me. I have the following Data Template in App.xaml: <Application.Resources> <DataTemplate> <TextBox Name="txt1"/> <TextBox Name="txt2"/> </DataTemplate> </Application.Resources> I have a ListBox with the following Data Template: <ListBox> <ListBox.ItemTemplate> <DataTemplate> <TextBox Name="txt1"/> <TextBox Name="txt2"/> </DataTemplate> <ListBox.ItemTemplate> <ListBox> The ListBox receives the following Class in the

(WPF)how to raise Datatemplate's Context MenuItem event

只谈情不闲聊 提交于 2019-12-13 05:06:56
问题 I have a listbox and its data template. Items of listbox are binded with a static source. In data template I have a button, and created context menu of it and some menu items. <ObjectDataProvider x:Key="GlobalUnits"/> <DataTemplate x:Key="listboxTemplate" DataType="UnitClass"> <StackPanel Margin="3" > <DockPanel > <Button DockPanel.Dock="Left" Margin="5,0,10,0"> <Button.ContextMenu> <ContextMenu x:Name="CMUnits" Opened="OnContextMenuOpened" MenuItem.Click="OnMenuItemClick"> <MenuItem Header=

WPF DataTemplate performance

北城以北 提交于 2019-12-13 05:06:11
问题 Well the problem here is that if you have one DataTemplate for a type of object, each time the object is present, the DataTemplate will be created, that sounds about right. My problem is that our DataTemplate is sort of heavy AND the app could have around 1000 objects using that DataTemplate. I created a simplistic example where I created 5 Person objects and I bind them to a ListView. The DataTemplate for the Person object is a Grid with a Label and a ContextMenu with 2 MenuItems. For

How to update combobox value on changing selection c# dynamically using Binding() in c# (not xaml)

橙三吉。 提交于 2019-12-13 05:04:49
问题 I am c# silverlight5 beginner and i have a situation that i have to created a combo box dynamically using c# and kept items in it. But the problem now when i run it run properly showing the last value by default but when i select the another value it don't update the that value in the text box near by because it is not working dynamically. I guess i need to add some selection changed or some other event using c#. But i dont know how to do that. Please note that i have created this combo box

Binding image to property in wpf with image from resources

别来无恙 提交于 2019-12-13 05:02:12
问题 i have some pictures included to my project. this line of code works fine: <Image Stretch="UniformToFill" Source="/Images/OffsetSituations/offsetsituation1.jpg" but i have to change the picture from the VM so i made a property to bind to: private ImageSource _image; public ImageSource Image { get { return _image; } set { if (_image == value) return; _image = value; RaisePropertyChanged("Image"); } } from another post here on stackoverflow i got this code and changed it a bit: string picture =

Service Reference Error when trying to update or remove/add

柔情痞子 提交于 2019-12-13 04:46:40
问题 I have been searching for an answer to my service reference error for days now with no change. I made some changes to this web app a few months ago and I was able to update the service reference without any issue. Now, I made pretty much identical changes recently, but cannot update the service reference in the solution without an error: There was an error downloading 'http://localhost:57903/CreateServiceCall.xamlx/_vti_bin/ListData.svc/$metadata'. The request failed with the error message: .