Search Results

Search found 854 results on 35 pages for 'databinding'.

Page 18/35 | < Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >

  • Wrapping with Dependency Properties

    - by Chris
    I've got a Windows Forms control that I'm wrapping with a WindowsFormsHost-derived class to access WPF's data binding functionality. The Forms control exposes properties that indicate its state, along with the standard property-changed event notifier. For example, a Zoom property on the Forms control is accompanied with a ZoomChanged event. In the WindowsFormsHost wrapper, I'm using a DependencyProperty to represent the underlying Windows Forms control property. Binding works as expected going to the control; however, I'm not sure how to correctly propogate property changes from the wrapped control back out to binding subscribers (i.e., the Windows Form control changes its Zoom property and raises the ZoomChanged event). Any ideas on how to accomplish this? Should I be using a different approach?

    Read the article

  • How can I model the data in a multi-language data editor in WPF with MVVM?

    - by Patrick Szalapski
    Are there any good practices to follow when designing a model/ViewModel to represent data in an app that will view/edit that data in multiple languages? Our top-level class--let's call it Course--contains several collection properties, say Books and TopicsCovered, which each might have a collection property among its data. For example, the data needs to represent course1.Books.First().Title in different languages, and course1.TopicsCovered.First().Name in different languages. We want a app that can edit any of the data for one given course in any of the available languages--as well as edit non-language-specific data, perhaps the Author of a Book (i.e. course1.Books.First().Author). We are having trouble figuring out how best to set up the model to enable binding in the XAML view. For example, do we replace (in the single-language model) each String with a collection of LanguageSpecificString instances? So to get the author in the current language: course1.Books.First().Author.Where(Function(a) a.Language = CurrentLanguage).SingleOrDefault If we do that, we cannot easily bind to any value in one given language, only to the collection of language values such as in an ItemsControl. <TextBox Text={Binding Author.???} /> <!-- no way to bind to the current language author --> Do we replace the top-level Course class with a collection of language-specific Courses? So to get the author in the current language: course1.GetLanguage(CurrentLanguage).Books.First.Author If we do that, we can only easily work with one language at a time; we might want a view to show one language and let the user edit the other. <TextBox Text={Binding Author} /> <!-- good --> <TextBlock Text={Binding ??? } /> <!-- no way to bind to the other language author --> Also, that has the disadvantage of not representing language-neutral data as such; every property (such as Author) would seem to be in multiple languages. Even non-string properties would be in multiple languages. Is there an option in between those two? Is there another way that we aren't thinking of? I realize this is somewhat vague, but it would seem to be a somewhat common problem to design for. Note: This is not a question about providing a multilingual UI, but rather about actually editing multi-language data in a flexible way.

    Read the article

  • Binding a property to change the listbox items foreground individually for each item

    - by Eyal-Shilony
    I'm trying to change the foreground color of the items in the ListBox individually for each item, I've already posted a similar question but this one is more concrete. I hoped that the state of the color is reserved for each item added to the ListBox, so I tried to create a property (in this case "HotkeysForeground"), bind it and change the color when the items are added in the "HotkeyManager_NewHotkey" event, the problem it's changing the foreground color for all the items in the ListBox. How can I do that per item ? Here is the ViewModel I use. namespace Monkey.Core.ViewModel { using System; using System.Collections.ObjectModel; using System.Windows.Media; using Monkey.Core.SystemMonitor.Accessibility; using Monkey.Core.SystemMonitor.Input; public class MainWindowViewModel : WorkspaceViewModel { private readonly FocusManager _focusManager; private readonly HotkeyManager _hotkeyManager; private readonly ObservableCollection<string> _hotkeys; private Color _foregroundColor; private string _title; public MainWindowViewModel() { _hotkeys = new ObservableCollection<string>(); _hotkeyManager = new HotkeyManager(); _hotkeyManager.NewHotkey += HotkeyManager_NewHotkey; _focusManager = new FocusManager(); _focusManager.Focus += FocusManager_Focus; } public Color HotkeysForeground { get { return _foregroundColor; } set { _foregroundColor = value; OnPropertyChanged(() => HotkeysForeground); } } public ReadOnlyObservableCollection<string> Hotkeys { get { return new ReadOnlyObservableCollection<string>(_hotkeys); } } public string Title { get { return _title; } set { _title = value; OnPropertyChanged(() => Title); } } protected override void OnDispose() { base.OnDispose(); _hotkeyManager.Dispose(); _focusManager.Dispose(); } private void FocusManager_Focus(object sender, FocusManagerEventArgs e) { Title = e.Title; } private void HotkeyManager_NewHotkey(object sender, EventArgs eventArgs) { HotkeysForeground = _hotkeys.Count <= 2 ? Colors.Blue : Colors.Brown; _hotkeys.Clear(); foreach (var hotkey in _hotkeyManager.GetHotkeys()) { _hotkeys.Add(hotkey); } } } } Here is the view. <Window x:Class="Monkey.View.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespace:System;assembly=mscorlib" Title="{Binding Mode=OneWay, Path=Title, UpdateSourceTrigger=PropertyChanged}" Height="200" Width="200" ShowInTaskbar="False" WindowStyle="ToolWindow" Topmost="True" ResizeMode="CanResizeWithGrip" AllowsTransparency="False"> <Window.Resources> <SolidColorBrush Color="{Binding HotkeysForeground}" x:Key="HotkeysBrush"/> </Window.Resources> <ListBox Canvas.Left="110" Canvas.Top="74" Name="HotkeyList" Height="Auto" Width="Auto" HorizontalContentAlignment="Left" BorderThickness="0" ScrollViewer.CanContentScroll="False" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled" ItemsSource="{Binding Path=Hotkeys}" VerticalAlignment="Stretch" VerticalContentAlignment="Center" FontSize="20"> <ListBox.ItemContainerStyle> <Style TargetType="ListBoxItem"> <Setter Property="IsEnabled" Value="False" /> </Style> </ListBox.ItemContainerStyle> <ListBox.ItemTemplate> <DataTemplate> <Label Content="{Binding}" Foreground="{StaticResource HotkeysBrush}"/> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </Window> Thank you in advance.

    Read the article

  • Why is two-way binding in silverlight not working?

    - by Edward Tanguay
    According to how Silverlight TwoWay binding works, when I change the data in the FirstName field, it should change the value in CheckFirstName field. Why is this not the case? ANSWER: Thank you Jeff, that was it, for others: here is the full solution with downloadable code. XAML: <StackPanel> <Grid x:Name="GridCustomerDetails"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="300"/> </Grid.ColumnDefinitions> <TextBlock VerticalAlignment="Center" Margin="10" Grid.Row="0" Grid.Column="0">First Name:</TextBlock> <TextBox Margin="10" Grid.Row="0" Grid.Column="1" Text="{Binding FirstName, Mode=TwoWay}"/> <TextBlock VerticalAlignment="Center" Margin="10" Grid.Row="1" Grid.Column="0">Last Name:</TextBlock> <TextBox Margin="10" Grid.Row="1" Grid.Column="1" Text="{Binding LastName}"/> <TextBlock VerticalAlignment="Center" Margin="10" Grid.Row="2" Grid.Column="0">Address:</TextBlock> <TextBox Margin="10" Grid.Row="2" Grid.Column="1" Text="{Binding Address}"/> </Grid> <Border Background="Tan" Margin="10"> <TextBlock x:Name="CheckFirstName"/> </Border> </StackPanel> Code behind: public Page() { InitializeComponent(); Customer customer = new Customer(); customer.FirstName = "Jim"; customer.LastName = "Taylor"; customer.Address = "72384 South Northern Blvd."; GridCustomerDetails.DataContext = customer; Customer customerOutput = (Customer)GridCustomerDetails.DataContext; CheckFirstName.Text = customer.FirstName; }

    Read the article

  • How to handle a DataTemplate creation

    - by Shimmy
    Hello! Take a look at the following xaml: <ListBox ItemsSource="{Binding}"> <ListBox.Resources> <CollectionViewSource x:Key="CVS"/> </ListBox.Resources> <ListBox.DataTemplate> <DataTemplate OnBinding="myBinding"> <ListBox DataContext="{StaticResource CVS}" ItemsSource="{Binding}" /> </DataTemplate> </ListBox.DataTemplate> </ListBox> So I can handle the binding and manually retrieve the CVS and set its Source property to my custom stuff according to the DataTemplate's DataContext. Or else there is a different way in doing it. Any ideas are welcommed!

    Read the article

  • DataTable won't DataBind with a DataTable.NewRow()

    - by David
    Is DataRow.NewRow() insufficient as the only row in a DataTable? I would expect this to work, but it doesn't. It's near the end of my Page_Load inside my If(!Postback) block. gridCPCP is GridView DataTable dt = new DataTable(); dt.Columns.Add("ID", int.MinValue.GetType()); dt.Columns.Add("Code", string.Empty.GetType()); dt.Columns.Add("Date", DateTime.MinValue.GetType()); dt.Columns.Add("Date2", DateTime.MinValue.GetType()); dt.Columns.Add("Filename", string.Empty.GetType()); //code to add rows if (dt.Rows.Count > 0) { gridCPCP.DataSource = dt; gridCPCP.DataBind(); } else { dt.Rows.Add(dt.NewRow()); gridCPCP.DataSource = dt; gridCPCP.DataBind(); //EXCEPTION int TotalColumns = gridCPCP.Rows[0].Cells.Count; gridCPCP.Rows[0].Cells.Clear(); gridCPCP.Rows[0].Cells.Add(new TableCell()); gridCPCP.Rows[0].Cells[0].ColumnSpan = TotalColumns; gridCPCP.Rows[0].Cells[0].Text = "No Record Found"; } The exception throws on gridCPCP.DataBind() and only when execution reaches the else block. If there were rows added above via dt.Rows.Add(new object[] { ... } binding works. System.ArgumentOutOfRangeException: Length cannot be less than zero. Parameter name: length

    Read the article

  • Bind the value of a parameter in an ObjectDataProvider in WPF

    - by Andrei Rinea
    I would like to be able to be doing this : <ObjectDataProvider x:Key="dataProvider" ObjectInstance="uiRoot:App.Current.Controller" MethodName="GetMyViewModel"> <ObjectDataProvider.MethodParameters> <system:Int32>{Binding Id}</system:Int32> </ObjectDataProvider.MethodParameters> </ObjectDataProvider> The emphasis being on <system:Int32>{Binding Id}</system:Int32> I can't get around this. Any ideas? :(

    Read the article

  • Horrorble performance using ListViews with nested objects in WPF

    - by Christian
    Hi community, like mentioned in the title I get a horrible performance if I use ListViews with nested objects. My scenario is: Each row of a ListView presents an object of the class Transaction with following attributes: private int mTransactionID; private IBTTransactionSender mSender; private IBTTransactionReceiver mReceiver; private BTSubstrate mSubstrate; private double mAmount; private string mDeliveryNote; private string mNote; private DateTime mTransactionDate; private DateTime mCreationTimestamp; private BTEmployee mEmployee; private bool mImported; private bool mDescendedFromRecurringTransaction; Each attribute can be accessed by its corresponding property. An ObservableCollection<Transaction> is bound to the ItemsSource of a ListView. The ListView itself looks like the following: </ListView.GroupStyle> <ListView.View> <GridView> <GridViewColumn core:SortableListView.SortPropertyName="Transaction.ToSave" Width="80"> <GridViewColumnHeader Name="GVCHLoadedToSave" Style="{StaticResource ListViewHeaderStyle}">Speichern</GridViewColumnHeader> <GridViewColumn.CellTemplate> <DataTemplate> <Grid> <CheckBox Name="CBListViewItem" IsChecked="{Binding Path=Transaction.ToSave, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></CheckBox> </Grid> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn core:SortableListView.SortPropertyName="Transaction.TransactionDate" Width="80"> <GridViewColumnHeader Name="GVCHLoadedDate" Style="{StaticResource ListViewHeaderStyle}">Datum</GridViewColumnHeader> <GridViewColumn.CellTemplate> <DataTemplate> <Grid> <TextBlock Text="{Binding ElementName=DPDate, Path=Text}" Style="{StaticResource GridBlockStyle}"/> <toolkit:DatePicker Name="DPDate" Width="{Binding ElementName=GVCHDate, Path=ActualWidth}" SelectedDateFormat="Short" Style="{StaticResource GridEditStyle}" SelectedDate="{Binding Path=Transaction.TransactionDate, Mode=TwoWay}" SelectedDateChanged="DPDate_SelectedDateChanged"/> </Grid> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn core:SortableListView.SortPropertyName="Transaction.Sender.Description" Width="120"> <GridViewColumnHeader Name="GVCHLoadedSender" Style="{StaticResource ListViewHeaderStyle}">Von</GridViewColumnHeader> <GridViewColumn.CellTemplate> <DataTemplate> <Grid> <TextBlock Text="{Binding Path=Transaction.Sender.Description}" Style="{StaticResource GridBlockStyle}"/> <ComboBox Name="CBSender" Width="{Binding ElementName=GVCHSender, Path=ActualWidth}" SelectedItem="{Binding Path=Transaction.Sender}" DisplayMemberPath="Description" Text="{Binding Path=Sender.Description, Mode=OneWay}" ItemsSource="{Binding ElementName=Transaction, Path=SenderList}" Style="{StaticResource GridEditStyle}"> </ComboBox> </Grid> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn core:SortableListView.SortPropertyName="Transaction.Receiver.Description" Width="120"> <GridViewColumnHeader Name="GVCHLoadedReceiver" Style="{StaticResource ListViewHeaderStyle}">Nach</GridViewColumnHeader> <GridViewColumn.CellTemplate> <DataTemplate> <Grid> <TextBlock Text="{Binding Path=Transaction.Receiver.Description}" Style="{StaticResource GridBlockStyle}"/> <ComboBox Name="CBReceiver" Width="{Binding ElementName=GVCHReceiver, Path=ActualWidth}" SelectedItem="{Binding Path=Transaction.Receiver}" DisplayMemberPath="Description" Text="{Binding Path=Receiver.Description, Mode=OneWay}" ItemsSource="{Binding ElementName=Transaction, Path=ReceiverList}" Style="{StaticResource GridEditStyle}"> </ComboBox> </Grid> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn core:SortableListView.SortPropertyName="Transaction.Substrate.Description" Width="140"> <GridViewColumnHeader Name="GVCHLoadedSubstrate" Style="{StaticResource ListViewHeaderStyle}">Substrat</GridViewColumnHeader> <GridViewColumn.CellTemplate> <DataTemplate> <Grid> <TextBlock Text="{Binding Path=Transaction.Substrate.Description}" Style="{StaticResource GridBlockStyle}"/> <ComboBox Name="CBSubstrate" Width="{Binding ElementName=GVCHSubstrate, Path=ActualWidth}" SelectedItem="{Binding Path=Transaction.Substrate}" DisplayMemberPath="Description" Text="{Binding Path=Substrate.Description, Mode=OneWay}" ItemsSource="{Binding ElementName=Transaction, Path=SubstrateList}" Style="{StaticResource GridEditStyle}"> </ComboBox> </Grid> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn core:SortableListView.SortPropertyName="Transaction.Amount" Width="80"> <GridViewColumnHeader Name="GVCHLoadedAmount" Style="{StaticResource ListViewHeaderStyle}">Menge [kg]</GridViewColumnHeader> <GridViewColumn.CellTemplate> <DataTemplate> <Grid> <TextBlock Text="{Binding Path=Transaction.Amount}" Style="{StaticResource GridBlockStyle}"/> <TextBox Name="TBAmount" Text="{Binding Path=Transaction.Amount, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="{Binding ElementName=GVCHAmount, Path=ActualWidth}" Style="{StaticResource GridTextBoxStyle}" /> </Grid> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn core:SortableListView.SortPropertyName="Transaction.DeliveryNote" Width="100"> <GridViewColumnHeader Name="GVCHLoadedDeliveryNote" Style="{StaticResource ListViewHeaderStyle}">Lieferschein Nr.</GridViewColumnHeader> <GridViewColumn.CellTemplate> <DataTemplate> <Grid> <TextBlock Text="{Binding Path=Transaction.DeliveryNote}" Style="{StaticResource GridBlockStyle}"/> <TextBox Name="TBDeliveryNote" Text="{Binding Path=Transaction.DeliveryNote, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="{Binding ElementName=GVCHDeliveryNote, Path=ActualWidth}" Style="{StaticResource GridEditStyle}" /> </Grid> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn core:SortableListView.SortPropertyName="Transaction.Note" Width="190"> <GridViewColumnHeader Name="GVCHLoadedNote" Style="{StaticResource ListViewHeaderStyle}">Bemerkung</GridViewColumnHeader> <GridViewColumn.CellTemplate> <DataTemplate> <Grid> <TextBlock Text="{Binding Path=Transaction.Note}" Style="{StaticResource GridBlockStyle}"/> <TextBox Name="TBNote" Text="{Binding Path=Transaction.Note, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="{Binding ElementName=GVCHNote, Path=ActualWidth}" Style="{StaticResource GridEditStyle}" /> </Grid> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn core:SortableListView.SortPropertyName="Transaction.Employee.LastName" Width="100"> <GridViewColumnHeader Name="GVCHLoadedEmployee" Style="{StaticResource ListViewHeaderStyle}">Mitarbeiter</GridViewColumnHeader> <GridViewColumn.CellTemplate> <DataTemplate> <Grid> <TextBlock Text="{Binding Path=Transaction.Employee.LastName}" Style="{StaticResource GridBlockStyle}"/> <ComboBox Name="CBEmployee" Width="{Binding ElementName=GVCHEmployee, Path=ActualWidth}" SelectedItem="{Binding Path=Transaction.Employee}" DisplayMemberPath="LastName" Text="{Binding Path=Employee.LastName, Mode=OneWay}" ItemsSource="{Binding ElementName=Transaction, Path=EmployeeList}" Style="{StaticResource GridEditStyle}"> </ComboBox> </Grid> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridView> </ListView.View> </ListView> As you can see in the screenshot the user got the possibility to change the values of the transaction attributes with comboboxes. Ok now to my problem. If I click on the "Laden" button the application will load about 150 entries in the ObservableCollection<Transaction>. Before I fill the collection I set the ItemsSource of the ListView to null and after filling I bind the collection to the ItemsSource once again. The loading itself takes a few milliseconds, but the rendering of the filled collection takes a long time (150 entries = about 20 sec). I tested to delete all Comboboxes out of the xaml and i got a better performance, because I don't have to fill the ComboBoxes for each row. But I need to have these comboboxes for modifing the attributes of the Transaction. Does anybody know how to improve the performance? THX

    Read the article

  • Trouble binding command in grid menu item.

    - by Pete
    I have a grid that's inside a usercontrol derived class called MediatedUserControl. I'm adding a context menu to let the user delete an item, but I've been unable to figure out how to bind the command to my command property. I'm using MVVM and my viewmodel implements a public ICommand property called DeleteSelectedItemCommand. However, when the view is displayed, I get the following message in the output window: System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='BRO.View.MediatedUserControl', AncestorLevel='1''. BindingExpression:Path=DataContext.DeleteSelectedItemCommand; DataItem=null; target element is 'BarButtonItem' (HashCode=6860584); target property is 'Command' (type 'ICommand') I feel like I generally have a good handle on bindings like this and can't figure out what it is I'm missing here. Thanks for any help you can provide. <dxg:GridControl HorizontalAlignment="Left" Margin="12,88,0,0" x:Name="gridControl1" VerticalAlignment="Top" Height="500" Width="517" DataSource="{Binding ItemList}" BorderBrush="{StaticResource {x:Static SystemColors.ActiveBorderBrushKey}}" ShowBorder="True" Background="{StaticResource {x:Static SystemColors.ControlLightBrushKey}}" UseLayoutRounding="False" DataContext="{Binding}"> <dxg:GridControl.Columns> <dxg:GridColumn FieldName="Code" Header="Code" Width="107" /> <dxg:GridColumn FieldName="Name" Header="Item" Width="173" /> <dxg:GridColumn FieldName="PricePerItem" Header="Unit Price" Width="70"> <dxg:GridColumn.EditSettings> <dxe:TextEditSettings DisplayFormat="N2" /> </dxg:GridColumn.EditSettings> </dxg:GridColumn> <dxg:GridColumn FieldName="Quantity" Header="Qty" Width="50" AllowEditing="True" /> <dxg:GridColumn FieldName="TotalPrice" Header="Total Price" Width="90"> <dxg:GridColumn.EditSettings> <dxe:TextEditSettings DisplayFormat="N2" /> </dxg:GridColumn.EditSettings> </dxg:GridColumn> </dxg:GridControl.Columns> <dxg:GridControl.View> <dxg:TableView ShowIndicator="False" ShowGroupPanel="False" MultiSelectMode="Row" AllowColumnFiltering="False" AllowBestFit="False" AllowFilterEditor="False" AllowEditing="False" AllowGrouping="False" AllowSorting="False" AllowResizing="False" AllowMoving="False" AllowMoveColumnToDropArea="False" AllowDateTimeGroupIntervalMenu="False" > <dxg:TableView.RowCellMenuCustomizations> <dxb:BarButtonItem Name="deleteRowItem" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=view:MediatedUserControl, AncestorLevel=1}, Path=DataContext.DeleteSelectedItemCommand}"> </dxb:BarButtonItem> </dxg:TableView.RowCellMenuCustomizations> </dxg:TableView> </dxg:GridControl.View>

    Read the article

  • Setting nested object to null when selected option has empty value

    - by Javi
    Hello, I have a Class which models a User and another which models his country. Something like this: public class User{ private Country country; //other attributes and getter/setters } public class Country{ private Integer id; private String name; //other attributes and getter/setters } I have a Spring form where I have a combobox so the user can select his country or can select the undefined option to indicate he doen't want to provide this information. So I have something like this: <form:select path="country"> <form:option value="">-Select one-</form:option> <form:options items="${countries}" itemLabel="name" itemValue="id"/> </form:select> In my controller I get the autopopulated object with the user information and I want to have country set to null when the "-Select one-" option has been selected. So I have set a initBinder with a custom editor like this: @InitBinder protected void initBinder(WebDataBinder binder) throws ServletException { binder.registerCustomEditor(Country.class, "country", new CustomCountryEditor()); } and my editor do something like this: public class CustomCountryEditor(){ @Override public String getAsText() { //I return the Id of the country } @Override public void setAsText(String str) { //I search in the database for a country with id = new Integer(str) //and set country to that value //or I set country to null in case str == null } } When I submit the form it works because when I have country set to null when I have selected "-Select one-" option or the instance of the country selected. The problem is that when I load the form I have a method like the following one to load the user information. @ModelAttribute("user") public User getUser(){ //loads user from database } The object I get from getUser() has country set to a specific country (not a null value), but in the combobox is not selected any option. I've debugged the application and the CustomCountryEditor works good when setting and getting the text, thoughgetAsText method is called for every item in the list "countries" not only for the "country" field. Any idea? Is there a better way to set null the country object when I select no country option in the combobox? Thanks

    Read the article

  • WPF Binding with RelativeSource of Window Requires "DataContext" in Path?

    - by Phil Sandler
    The following code works, but I'm curious as to why I need the Path to be prefixed with "DataContext"? In most other cases, the path used is relative to DataContext. Is it because I am using a RelativeSource? Because the source is at the root level (Window)? <Style TargetType="TextBox"> <Setter Property="IsReadOnly" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.IsReadOnly}"/> </Style>

    Read the article

  • Binding ListBox ItemCount to IvalueConverter

    - by Ben
    Hi All, I am fairly new to WPF so forgive me if I am missing something obvious. I'm having a problem where I have a collection of AggregatedLabels and I am trying to bind the ItemCount of each AggregatedLabel to the FontSize in my DataTemplate so that if the ItemCount of an AggregatedLabel is large then a larger fontSize will be displayed in my listBox etc. The part that I am struggling with is the binding to the ValueConverter. Can anyone assist? Many thanks! XAML Snippet <DataTemplate x:Key="TagsTemplate"> <WrapPanel> <TextBlock Text="{Binding Name, Mode=Default}" TextWrapping="Wrap" FontSize="{Binding ItemCount, Converter={StaticResource CountToFontSizeConverter}, Mode=Default}" Foreground="#FF0D0AF7"/> </WrapPanel> </DataTemplate> <ListBox x:Name="tagsList" ItemsSource="{Binding AggregatedLabels, Mode=Default}" ItemTemplate="{StaticResource TagsTemplate}" Style="{StaticResource tagsStyle}" Margin="200,10,16.171,11.88" /> AggregatedLabel Collection using (DB2DataReader dr = command.ExecuteReader()) { while (dr.Read()) { AggregatedLabelModel aggLabel = new AggregatedLabelModel(); aggLabel.ID = Convert.ToInt32(dr["LABEL_ID"]); aggLabel.Name = dr["LABEL_NAME"].ToString(); LabelData.Add(aggLabel); } } Converter public class CountToFontSizeConverter : IValueConverter { #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { const int minFontSize = 6; const int maxFontSize = 38; const int increment = 3; int count = (int)value; if ((minFontSize + count + increment) < maxFontSize) { return minFontSize + count + increment; } return maxFontSize; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } #endregion } AggregatedLabel Class public class AggregatedLabelModel { public int ID { get; set; } public string Name { get; set; } } CollectionView ListCollectionView labelsView = new ListCollectionView(LabelData); labelsView.GroupDescriptions.Add(new PropertyGroupDescription("Name"));

    Read the article

  • ASP.NET configure data source is not returning anything?

    - by Greg McNulty
    I'm selecting table data of the current user: SELECT [ConfidenceLevel], [LoveLevel], [HappinessLevel] FROM [UserData] WHERE ([UserProfileID] = @UserProfileID) I have set a control to the unique user ID and it is getting the correct value: HTML: <asp:Label ID="userID" runat="server" Text="Labeluser"></asp:Label> C#: userID.Text = Membership.GetUser().ProviderUserKey.ToString(); I then use it in the where clause using the Configure Data Source window unique ID = control then controlID userID (fills in .text for me) I compile and run but nothing shows up where the table should be. Any suggestions? Here is the code it has created: <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"> <Columns> <asp:BoundField DataField="ConfidenceLevel" HeaderText="ConfidenceLevel" SortExpression="ConfidenceLevel" /> <asp:BoundField DataField="LoveLevel" HeaderText="LoveLevel" SortExpression="LoveLevel" /> <asp:BoundField DataField="HappinessLevel" HeaderText="HappinessLevel" SortExpression="HappinessLevel" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringToDB %>" SelectCommand="SELECT [ConfidenceLevel], [LoveLevel], [HappinessLevel] FROM [UserData] WHERE ([UserProfileID] = @UserProfileID)"> <SelectParameters> <asp:ControlParameter ControlID="userID" Name="UserProfileID" PropertyName="Text" Type="Object" /> </SelectParameters> </asp:SqlDataSource>

    Read the article

  • How to properly set a datatable to an gridview in code with an ObjectDataSource?

    - by Xaisoft
    Hello, I have an ObjectDataSource with an ID of ObjectDataSource1 on a webpage. I also have a gridview in which I am binding the ObjectDataSource.ID to the GridView.DataSourceID. The problem I get is when text is changed in a textbox, the code calls BrokerageTransactions.GetAllWithDt which returns a DataTable. I want to set this datatable as the DataSource for the GridView, but it is telling me that I can't set the DataSouce and DataSourceId together. How can I fix this? Code is below. Also. Why can't you set a DataSourceID and a DataSource when using an ObjectDataSource? Thanks, X protected void BrokerageChange(Object sender, EventArgs e) { BrokerageTransactions brokerageaccountdetails = new BrokerageTransactions(); DataSet ds = BrokerageAccount.GetBrkID2(new Guid(Membership.GetUser().ProviderUserKey.ToString()), ddlBrokerageDetails.SelectedItem.Text.ToString()); foreach (DataRow dr in ds.Tables[0].Rows) { brokerageaccountdetails.BrokerageId = new Guid(dr["BrkrgId"].ToString()); } ddlBrokerageDetails.SelectedItem.Value = brokerageaccountdetails.BrokerageId.ToString(); if (txtTransactionsTo.Text != "" && txtTransactionsFrom.Text != "") ObjectDataSource1.FilterExpression = "convert(CreateDt,System.DateTime)>Convert('" + Convert.ToDateTime(txtTransactionsFrom.Text) + "',System.DateTime) and Convert(CreateDt,System.DateTime)<convert('" + Convert.ToDateTime(txtTransactionsTo.Text.ToString()) + "',System.DateTime)"; else if (txtTransactionsFrom.Text != "") ObjectDataSource1.FilterExpression = "convert(CreateDt,System.DateTime)>convert('" + Convert.ToDateTime(txtTransactionsFrom.Text) + "',System.DateTime)"; else if (txtTransactionsTo.Text != "") ObjectDataSource1.FilterExpression = "convert(CreateDt,System.DateTime) <convert('" + Convert.ToDateTime(txtTransactionsTo.Text.ToString()) + "',System.DateTime)"; else ObjectDataSource1.FilterExpression = " "; grvBrokerage.DataSourceID = ObjectDataSource1.ID; grvBrokerage.DataBind(); DateTime dtTransFrom = Convert.ToDateTime("1/1/1900"); DateTime dtTransTo = System.DateTime.Today; //TransactionsTo Box is Empty if ((txtTransactionsFrom.Text.Length > 2) && (txtTransactionsTo.Text.Length < 2)) { dtTransFrom = Convert.ToDateTime(txtTransactionsFrom.Text); dtTransTo = System.DateTime.Today; } //TransactionsFrom Box is Empty if ((txtTransactionsFrom.Text.Length < 2) && (txtTransactionsTo.Text.Length > 2)) { dtTransFrom = Convert.ToDateTime("1/1/1900"); dtTransTo = Convert.ToDateTime(txtTransactionsTo.Text); } //TransactionsFrom Box and TransactionsTo Box is Not Empty if ((txtTransactionsFrom.Text.Length > 2) && (txtTransactionsTo.Text.Length > 2)) { dtTransFrom = Convert.ToDateTime(txtTransactionsFrom.Text); dtTransTo = Convert.ToDateTime(txtTransactionsTo.Text); } // Fails Here grvBrokerage.DataSource = BrokerageTransactions.GetAllWithDt(brokerageaccountdetails.BrokerageId, dtTransFrom, dtTransTo); grvBrokerage.DataBind(); }

    Read the article

  • ToolStripComboBox.SelectedItem change does not propagate to binding source

    - by Marius
    My binding is set up as this: _selectXAxisUnitViewModelBindingSource = new BindingSource(); _selectXAxisUnitViewModelBindingSource.DataSource = typeof(SelectXAxisUnitViewModel); _selectedUnitComboBoxBindingSource = new BindingSource(); _selectedUnitComboBoxBindingSource.DataSource = _selectXAxisUnitViewModelBindingSource; _selectedUnitComboBoxBindingSource.DataMember = "AvailableUnits"; _selectedUnitComboBox.ComboBox.DataSource = _selectedUnitComboBoxBindingSource; _selectedUnitComboBox.ComboBox.DisplayMember = String.Empty; _selectedUnitComboBox.ComboBox.ValueMember = String.Empty; _selectedUnitComboBox.ComboBox.DataBindings.Add("SelectedItem", _selectXAxisUnitViewModelBindingSource, "SelectedUnit", true, DataSourceUpdateMode.OnPropertyChanged); // this is a bug in the .Net framework: http://connect.microsoft.com/VisualStudio/feedback/details/473777/toolstripcombobox-nested-on-toolstripdropdownbutton-not-getting-bindingcontext _selectedUnitComboBox.ComboBox.BindingContext = this.BindingContext; The property "AvailableUnits" is a collection of strings and the "SelectedUnit" is a string-property. Now the dropdown list is populated as expected, but when I select and item in the list, the change is not propagated to the binding source. Any idea what I am doing wrong?

    Read the article

  • Accessing Linq data in telerik grid ItemCreated method

    - by Jack
    Not sure if the title of this question makes sense, but here's my problem: I have a telerik grid bound to a Linq data object, however, I limit the fields returned: <IQueryable>filter = data.Select(x => new {x.ID, x.Name, x.Age}); I would like to access these fields in the ItemCreated method of the grid: protected void rgPeople_ItemCreated(object sender, GridItemEventArgs e) { Telerik.Web.UI.GridDataItem item = (GridDataItem)e.Item; ?????? Person = (???????)e.Item.DataItem; } What do I declare ?????? as so that I can use: String ID = Person.ID; String Name = Person.Name; etc

    Read the article

  • Wpf binding with nested properties

    - by byte
    ViewModel I have a property of type Member called KeyMember. The 'Member' type has an ObservableCollection called Addresses. The Address is composed of two strings - street and postcode . View I have a ListBox whose item source need to be set to ViewModels's KeyMember property and it should display the Street of all the Past Addresses in the collection. Question My ViewModel and View relationship is established properly. I am able to write a data template for the above simple case as below <ListBox ItemsSource="{Binding KeyMember.Addresses}"> <ListBox.ItemTemplate> <DataTemplate DataType="Address"> <TextBlock Text="{Binding Street}"/> </DataTemplate> </ListBox.ItemTemplate> </ListBox> How would I write the DataTemplate if I change KeyMember from type Member to ObservableCollection< Member assuming that the collection has only one element. PS: I know that for multiple elements in collection, I will have to implement the Master-Detail pattern/scenario.

    Read the article

  • strange Problem with WPF Textbox stringformat - Cursor moves back

    - by Emad
    I am using WPF 4.0 TextBox and binding. I am using StringFormat to format the number as currency. the XAML looks like this: <TextBox Text="{Binding Path=ValueProperty, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, StringFormat={}{0:C}, UpdateSourceTrigger=PropertyChanged}"> </TextBox> Everything seems to work correctly except for a strange behavior: When for example a user types in 12: right after typing 1, the value in the textbox becomes $1.00 and the weird thing is the the cursor is moved to be between the $ and the 1. So when a user simply types in 12, the result becomes $21.00. How can I fix this strange behavior?

    Read the article

  • Cannot edit values of DataGridView bound to a BindingList

    - by m_oLogin
    Hello community, I have trouble editing a databound bindinglist. Let me illustrate it with the following: Say I have the Person class: public Class Person{ private string m_firstname; private string m_lastname; public string FirstName{get;set;} public string LastName{get;set;} public Person{ ... } } I then have a containing class called Population: public class Population{ private BindingList<Person> m_lstPerson = new BindingList<Person>(); private string m_countryName; public BindingList<Person> ListPerson{get; set;} public string CountryName { get; set; } } I then have on one form a first datagridview with DataSource = m_lstPopulation (BindingList). The binding works like a charm when working with the Population objects. When I double click, it opens up a dialog form showing the object details. One tab in the details holds a datagridview bound to that population's ListPerson. The second datagridview displays fine. However, I cannot edit or add cells in this datagridview. None of the columns is set to read-only. In fact, both datagridview have just about the same parameters. What am I missing? It seems that a lock has been placed on the Population object so that its inner fields cannot be edited... Please advise. Thanks.

    Read the article

  • Is it possible to bind data asynchronously between two dropdownlists in a view?

    - by user252160
    I'd like to achieve the following effect using ASP.NET MVC and JQuery. I've got a drop down list displaying a list of Countries. I want to make it so that when I change the value of the country, a new drop down list appears below it, showing a list of companies whose country of origin is the particular selected company. The thing is that I do not want to rely too much on controller actions because I'm using it in a Template Helper which is a "headless" view. Can I bind it somehow?

    Read the article

  • Ajax data two-way data binding strategies?

    - by morgancodes
    I'd like to 1) Draw create form fields and populate them with data from javascript objects 2) Update those backing objects whenever the value of the form field changes Number 1 is easy. I have a few js template systems I've been using that work quite nicely. Number 2 may require a bit of thought. A quick google search on "ajax data binding" turned up a few systems which seem basically one-way. They're designed to update a UI based on backing js objects, but don't seem to address the question of how to update those backing objects when changes are made to the UI. Can anyone recommend any libraries which will do this for me? It's something I can write myself without too much trouble, but if this question has already been thought through, I'd rather not duplicate the work.

    Read the article

  • Bind Data after TCP receive.

    - by gtas
    I have this strange problem all day now. I dunno if you handled something similar. I used two different serializers and now i know its not this problem. Im sending some data over TCP Sockets. Serialize - Send - Deserialize, everything works ok, i can get my objects search through them, use they're properties! But, if e.g receive a BusinessObject[] and convert into List<BusinessObject>, then bind the list in a Control.DataSource = businessObjectList; BOOM! NotSupportedException. Tried it with 3 different controls. Same behaviour. My head is empty of ideas right now!! The Send TCP happens on Desktop Framework, Receive on Compact Framework. But i dont think this has to do with anything. I wish for an explanation on this!

    Read the article

  • Beginner question: What is binding?

    - by JDelage
    Hi, I was trying to understand the difference between early and late binding, and in the process realized that the concept of binding is nebulous to me. I think I understand that it relates to the way data-as-a-word-of-memory is linked to type-as-a-set-of-language-features but I am not sure those are the right concepts. Also, how does understanding this deeply help people become better programmers? Please note: This question is not "what is late v. early binding" or "what are the trade-offs between the 2". Those already exist here. Thanks, JDelage

    Read the article

  • WPF ItemsControl binding and the item order

    - by user109534
    I have ItemsControl in a WPF application, which is bind to an array of objects. And I am using ItemTemplate to render the list. I want to display for each item in the list the item order, like for example Customer 1 Name : xxxxx Age: 9999 Customer 2 Name : yyyy Age: 8888 Any idea how to do it Thanks

    Read the article

  • WPF binding behaviour different when bound property is declared as interface vs class type?

    - by Jay
    This started with weird behaviour that I thought was tied to my implementation of ToString(), and I asked this question: http://stackoverflow.com/questions/2916068/why-wont-wpf-databindings-show-text-when-tostring-has-a-collaborating-object It turns out to have nothing to do with collaborators and is reproducible. When I bind Label.Content to a property of the DataContext that is declared as an interface type, ToString() is called on the runtime object and the label displays the result. When I bind TextBlock.Text to the same property, ToString() is never called and nothing is displayed. But, if I change the declared property to a concrete implementation of the interface, it works as expected. Is this somehow by design? If so, any idea why? To reproduce: Create a new WPF Application (.NET 3.5 SP1) Add the following classes: public interface IFoo { string foo_part1 { get; set; } string foo_part2 { get; set; } } public class Foo : IFoo { public string foo_part1 { get; set; } public string foo_part2 { get; set; } public override string ToString() { return foo_part1 + " - " + foo_part2; } } public class Bar { public IFoo foo { get { return new Foo {foo_part1 = "first", foo_part2 = "second"}; } } } Set the XAML of Window1 to: <Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <StackPanel> <Label Content="{Binding foo, Mode=Default}"/> <TextBlock Text="{Binding foo, Mode=Default}"/> </StackPanel> </Window> in Window1.xaml.cs: public partial class Window1 : Window { public Window1() { InitializeComponent(); DataContext = new Bar(); } } When you run this application, you'll see the text only once (at the top, in the label). If you change the type of foo property on Bar class to Foo (instead of IFoo) and run the application again, you'll see the text in both controls.

    Read the article

< Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >