Search Results

Search found 226 results on 10 pages for 'propertychanged'.

Page 8/10 | < Previous Page | 4 5 6 7 8 9 10  | Next Page >

  • Silverlight: Problem using CellEditingTemplate

    - by Charles
    Hello Silverlight gurus, I am experiencing a problem with the DataGrid where my data-bound object's properties are not being updated when using the CellTemplate/CellEditingTemplate: <data:DataGridTemplateColumn Header="Text"> <data:DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding Text}" ></TextBlock> </DataTemplate> </data:DataGridTemplateColumn.CellTemplate> <data:DataGridTemplateColumn.CellEditingTemplate> <DataTemplate> <TextBox Text="{Binding Text, Mode=TwoWay}" /> </DataTemplate> </data:DataGridTemplateColumn.CellEditingTemplate> </data:DataGridTemplateColumn> I am binding to a code-gen'd entity via the RIA Services. I've added an event handler to the PropertyChanged event, and it is never fired. However, if I do not use a template and instead use a DataGridTextColumn, everything works fine. I'm sure this sounds like an easy fix - I'm only using a TextBox in my editing template, so why not us a DataGridTextColumn? The problem is that I want to have a multi-line textbox, so using the DataGridTextColumn is not an option. Any suggestions? Do you know of any differences between using a CellEditingTemplate containing a single TextBox and using a DataGridTextColumn? Thanks, -Charles [UPDATE] I posted a bug report here: http://silverlight.net/forums/p/118729/267521.aspx I can't imagine that this is "as-designed"... If someone else has known about this and I'm just being dumb, I'd appreciate an explanation - I'd prefer embarrassment over ignorance :).

    Read the article

  • Binding to an ObservableCollection attached property.

    - by bwreichle
    I want to create an attached property of type ObservableCollection<Notification> and bind it to a property of the same type on the DataContext. Currently I have: internal static class Squiggle { public static readonly DependencyProperty NotificationsProperty = DependencyProperty.RegisterAttached( "Notifications", typeof(ObservableCollection<Notification>), typeof(TextBox), new FrameworkPropertyMetadata(null, NotificationsPropertyChanged, CoerceNotificationsPropertyValue)); public static void SetNotifications(TextBox textBox, ObservableCollection<Notification> value) { textBox.SetValue(NotificationsProperty, value); } public static ObservableCollection<Notification> GetNotifications(TextBox textBox) { return (ObservableCollection<Notification>)textBox.GetValue(NotificationsProperty); } ... } With the following XAML: <TextBox x:Name="configTextBox" Text="{Binding Path=ConfigText, UpdateSourceTrigger=PropertyChanged}" AcceptsReturn="True" AcceptsTab="True" local:Squiggle.Notifications="{Binding Path=Notifications}" /> Unfortunatly, when I actually run this I get an exception stating: A 'Binding' cannot be used within a 'TextBox' collection. A 'Binding' can only be set on a DependencyProperty of a DependencyObject. This only seems to be a problem when the attached property is of type ObservableCollection so it seems like WPF is trying to do something magical when binding properties of this type and getting confused in the process. Anyone know what I need to do to make it work?

    Read the article

  • Set focus on textbox in WPF from view model (C#) & wPF

    - by priyanka.sarkar
    I have a TextBox and a Button in my view. Now I am checking a condition upon button click and if the condition turns out to be false, displaying the message to the user, and then I have to set the cursor to the text box control. if (companyref == null) { Lipper.Nelson.AdminClient.Main.Views.ContactPanels.CompanyAssociation cs = new Lipper.Nelson.AdminClient.Main.Views.ContactPanels.CompanyAssociation(); MessageBox.Show("Company does not exist.", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation); cs.txtCompanyID.Focusable = true; System.Windows.Input.Keyboard.Focus(cs.txtCompanyID); } The above code is in the view model. The CompanyAssociation is the view name. But the cursor is not getting set in the TextBox. The xaml is as under <igEditors:XamTextEditor KeyDown="xamTextEditorAllowOnlyNumeric_KeyDown" Name="txtCompanyID" ValueChanged="txtCompanyID_ValueChanged" Text="{Binding Company.CompanyId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="{Binding ActualWidth, ElementName=border}" Grid.Column="1" Grid.Row="0" VerticalAlignment="Top" Margin="0,5,0,0" HorizontalAlignment="Stretch" IsEnabled="{Binding Path=IsEditable}" /> <Button Template="{StaticResource buttonTemp1}" Command="{Binding ContactCommand}" CommandParameter="searchCompany" Content="Search" Width="80" Grid.Column="2" Grid.Row="0" VerticalAlignment="Top" Margin="0" HorizontalAlignment="Left" IsEnabled="{Binding Path=IsEditable}" /> Please help

    Read the article

  • WPF MVVM ViewModel constructor designmode

    - by Snake
    Right, I've got a main wpf window: <Window x:Class="NorthwindInterface.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ViewModels="clr-namespace:NorthwindInterface.ViewModels" Title="MainWindow" Height="350" Width="525"> <Window.DataContext> <ViewModels:MainViewModel /> </Window.DataContext> <ListView ItemsSource="{Binding Path=Customers}"> </ListView> </Window> And the MainViewModel is this: class MainViewModel : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged = delegate { }; public MainViewModel() { Console.WriteLine("test"); using (NorthwindEntities northwindEntities = new NorthwindEntities()) { this.Customers = (from c in northwindEntities.Customers select c).ToList(); } } public List<Customer> Customers { get;private set; } Now the problem is that in designermode I can't see my MainViewModel, it highlights it saying that it can't create an instance of the MainViewModel. It is connecting to a database. That is why (when I comment the code the problem is solved). But I don't want that. Any solutions on best practices around this?

    Read the article

  • reference from xaml to public class in .cs class file

    - by netmajor
    I have in my WPF project file RssInfo.cs in which I have public class public class DoubleRangeRule : ValidationRule { public double Min { get; set; } public double Max { get; set; } public override System.Windows.Controls.ValidationResult Validate(object value, CultureInfo cultureInfo) { ... } } and from my XAML code in WPF window class I neet to get to this DoubleRangeRule class.. //reference to my project, all my files are in the WpfCzytanieRSS namespace xmlns:valRule="clr-namespace:WpfCzytanieRSS;assembly=WpfCzytanieRSS" <TextBox Validation.ErrorTemplate="{StaticResource TextBoxErrorTemplate}" Name="tbTitle"> <TextBox.Text> <Binding Path="Nazwa" UpdateSourceTrigger="PropertyChanged"> <Binding.ValidationRules> <valRule:DoubleRangeRule Min="0.5" Max="10"/> //error place </Binding.ValidationRules> </Binding> </TextBox.Text> </TextBox> And i get two errors: Error 1 The tag 'DoubleRangeRule' does not exist in XML namespace 'clr-namespace:WpfCzytanieRSS;assembly=WpfCzytanieRSS'. Error 2 The type 'valRule:DoubleRangeRule' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built. Please help to get to class DoubleRangeRule ! :)

    Read the article

  • WPF Combobox Updates list but not the selected item

    - by JoshReedSchramm
    I have a combo box on a WPF form. On this form the user selects a record from the combo box which populates the rest of the fields on the form so the user can update that record. When they click save I am re-retrieving the combo box source which updates the combo box list. The problem is the selected item keeps the original label even though the data behind it is different. When you expand the combo box the selected item shows the right label. I am using a command binding mechanism. Here is some of the relevant code. private void SaveSalesRep() { BindFromView(); if (_salesRep.Id == 0) SalesRepRepository.AddAndSave(_salesRep); else SalesRepRepository.DataContext.SaveChanges(); int originalId = _salesRep.Id; InitSalesRepDropDown(); SalesRepSelItem = ((List<SalesRep>) SalesRepItems.SourceCollection).Find(x => x.Id == originalId); } private void InitSalesRepDropDown() { var salesRepRepository = IoC.GetRepository<ISalesRepRepository>(); IEnumerable<SalesRep> salesReps = salesRepRepository.GetAll(); _salesRepItems = new CollectionView(salesReps); NotifyPropertyChanged("SalesRepItems"); SalesRepSelItem = SalesRepItems.GetItemAt(0) as SalesRep; } The Selected Item property on the combo box is bound to SalesRepSelItem Property and the ItemsSource is bound to SalesRepItems which is backed by _salesRepItems. THe SalesRepSelItem property called NotifyPropertyChanges("SalesRepSelItem") which raises a PropertyChanged event. All told the binding of new items seems to work and the list updates, but the label on the selected item doesnt. Any ideas? Thanks all.

    Read the article

  • Silverlight 4 race condition with DataGrid master details control

    - by Simon_Weaver
    Basically I want a DataGrid (master) and details (textbox), where DataGrid is disabled during edit of details (forcing people to save/cancel)... Here's what I have... I have a DataGrid which serves as my master data. <data:DataGrid IsEnabled="{Binding CanLoad,ElementName=dsReminders}" ItemsSource="{Binding Data, ElementName=dsReminders}" > Its data comes from a DomainDataSource: <riaControls:DomainDataSource Name="dsReminders" AutoLoad="True" ... I have a bound Textbox which is the 'details' (very simple right now). There are buttons (Save/Cancel) which should be enabled when user tries to edit the text. Unfortunately Silverlight doesn't support UpdateSourceTrigger=PropertyChanged so I have to raise an event: <TextBox Text="{Binding SelectedItem.AcknowledgedNote, Mode=TwoWay, UpdateSourceTrigger=Explicit, ElementName=gridReminders}" TextChanged="txtAcknowledgedNote_TextChanged"/> The event to handle this calls BindingExpression.UpdateSource to update the source immediately: private void txtAcknowledgedNote_TextChanged(object sender, TextChangedEventArgs e) { BindingExpression be = txtAcknowledgedNote.GetBindingExpression(TextBox.TextProperty); be.UpdateSource(); } IN other words - typing in the textbox causes CanLoad of the DomainDataSource to become False (because we're editing). This in turn disables the DataGrid (IsEnabled is bound to it) and enables 'Cancel' and 'Save' buttons. However I'm running up against a race condition if I move quickly through rows in the DataGrid (just clicking random rows). The TextChanged presumably is being called on the textbox and confusing the DomainDataSource which then thinks there's been a change. So how should I disable the DataGrid while editing without having the race condition? One obvious solution would be to use KeyDown events to trigger the call to UpdateSource but I always hate having to do that.

    Read the article

  • How to dispatch a new property value in an object to the same property of two other objects

    - by WPFadvocate
    In WPF, I've three objects exposing the same DependencyProperty (let's say it's an integer). I want all three property values to remain synchronized, i.e. that whenever the int value changes in an object, this value is propagated to the two other objects. I think of multibinding to do the job, but I don't know how to detect which object changed, thus which value should be used and propagated to the other objects. Edited: here is my tentative code for multibinding, with the false hope that it would work without additional code: // create the multibinding MultiBinding mb = new MultiBinding() { Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; // create individual bindings to associate object_2 and object_3 to object_1 Binding b2 = new Binding() { Source = object_2, Path = new PropertyPath("X") }; Binding b3 = new Binding() { Source = object_3, Path = new PropertyPath("X") }; // add individual bindings to multibinding mb.Bindings.Add(b2); mb.Bindings.Add(b3); // bind object_2 and _3 to object_1 BindingOperations.SetBinding(object_1, TypeObject_1.XProperty, mb); But actually, there is a runtime error, saying the binding set by the last instruction is lacking a converter. But again I don't know how to write this converter (there is nothing to convert (as this is the case in the related MS sample of code linking 3 rgb properties to a color property), only to forward the value of the property changed to the two other properties). I understand I could solve the problem by creating an X_Changed event in the 3 types and then have each object registering to the two other objects event. I don't like this "manual" way and would prefer to bind the 3 properties together.

    Read the article

  • How to implement two way binding between an ActiveX control and a WPF MVVM View Model

    - by Zamboni
    I have a WPF application implemented using the MVVM framework that uses an ActiveX control and I need to keep the WPF and ActiveX UI synchronised. So far I can update the ActiveX UI when I change the WPF UI using the code at the bottom of the question that I got from the article Hosting an ActiveX Control in WPF and this question. But I cannot update the WPF UI when I make a change in the ActiveX UI. I suspect that I need to fire the PropertyChanged event from my ActiveX control but I have no idea how to do this or if it is even possible. The ActiveX controls I have written are in VB6 and MFC as I am just prototying at this time for the eventual integration of VB6 ActiveX controls in a WPF contaner application. Here is a code snipet that indicates the work done so far: System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost(); // Create the ActiveX control. AxTEXTBOXActiveXLib.AxTEXTBOXActiveX axWmp = new AxTEXTBOXActiveXLib.AxTEXTBOXActiveX(); // Assign the ActiveX control as the host control's child. host.Child = axWmp; axWmp.DataBindings.Add(new System.Windows.Forms.Binding("ActiveXStatus", (MainWindowViewModel)this.DataContext, "ModelStatus", true, DataSourceUpdateMode.OnPropertyChanged )); // Add the interop host control to the Grid // control's collection of child controls. this.activexRow.Children.Add(host); How to implement two way binding between an ActiveX control and a WPF MVVM View Model?

    Read the article

  • Interception with Unity in Prism v2 for WPF (not working for me)

    - by Bobby Chopra
    I cannot get interception to work with Prism v2 (Oct 2009). I am trying to intercept the Setter for any Public Properties and then fire the PropertyChanged event if the property has changed. I can see that the code gets executed (by stepping through with the debugger or adding a debug point). However, the WPF Window controls that are bound to these properties do not get updated. If I subscribe to these events and print to the console, I can print out the property change notifications. So, if the View has a textbox, which updates the property on the ViewModel, then the property in the ViewModel gets updated. However, if a button on the view (implemented as a DelegateCommand) causes the property to get updated, then the textbox (TwoWay Binding Mode) that is bound to that Property is not updated even though the event is triggered and the console has printed out the information about which property was updated. Has anyone encountered this issue? Here is the sample WPF Application that I have written. Wordpress doesn't allow uploads of zip files, so I renamed it to have a pdf extension (rename the file to have a zip extension). Please let me know what I am doing wrong. Thanks in advance.

    Read the article

  • XAML Binding to complex value objects

    - by Gus
    I have a complex value object class that has 1) a number or read-only properties; 2) a private constructor; and 3) a number of static singleton instance properties [so the properties of a ComplexValueObject never change and an individual value is instantiated once in the application's lifecycle]. public class ComplexValueClass { /* A number of read only properties */ private readonly string _propertyOne; public string PropertyOne { get { return _propertyOne; } } private readonly string _propertyTwo; public string PropertyTwo { get { return _propertyTwo; } } /* a private constructor */ private ComplexValueClass(string propertyOne, string propertyTwo) { _propertyOne = propertyOne; _propertyTwo = PropertyTwo; } /* a number of singleton instances */ private static ComplexValueClass _complexValueObjectOne; public static ComplexValueClass ComplexValueObjectOne { get { if (_complexValueObjectOne == null) { _complexValueObjectOne = new ComplexValueClass("string one", "string two"); } return _complexValueObjectOne; } } private static ComplexValueClass _complexValueObjectTwo; public static ComplexValueClass ComplexValueObjectTwo { get { if (_complexValueObjectTwo == null) { _complexValueObjectTwo = new ComplexValueClass("string three", "string four"); } return _complexValueObjectTwo; } } } I have a data context class that looks something like this: public class DataContextClass : INotifyPropertyChanged { private ComplexValueClass _complexValueClass; public ComplexValueClass ComplexValueObject { get { return _complexValueClass; } set { _complexValueClass = value; PropertyChanged(this, new PropertyChangedEventArgs("ComplexValueObject")); } } } I would like to write a XAML binding statement to a property on my complex value object that updates the UI whenever the entire complex value object changes. What is the best and/or most concise way of doing this? I have something like: <Object Value="{Binding ComplexValueObject.PropertyOne}" /> but the UI does not update when ComplexValueObject as a whole changes.

    Read the article

  • Set the caret/cursor position to the end of the string value WPF textbox

    - by Zamboni
    I am try to set the caret/cursor position to the end of the string value in my WPF textbox when I open my window for the first time. I use the FocusManager to set the focus on my textbox when my window opens. Nothing seems to work. Any ideas? Note, I am using the MVVM pattern, and I included only a portion of the XAML from my code. <Window FocusManager.FocusedElement="{Binding ElementName=NumberOfDigits}" Height="400" Width="800"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <TextBox Grid.Column="0" Grid.Row="0" x:Name="NumberOfDigits" IsReadOnly="{Binding Path=IsRunning, Mode=TwoWay}" VerticalContentAlignment="Center" Text="{Binding Path=Digits, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/> <Button Grid.Column="0" Grid.Row="1" Margin="10,0,10,0" IsDefault="True" Content="Start" Command="{Binding StartCommand}"/> </Grid> </Window>

    Read the article

  • pass Validation error to UI element in WPF?

    - by Tony
    I am using IDataErrorInfo to validate my data in a form in WPF. I have the validation implemented in my presenter. The actual validation is happening, but the XAML that's supposed to update the UI and set the style isn't happening. Here it is: <Style x:Key="textBoxInError" TargetType="{x:Type TextBox}"> <Style.Triggers> <Trigger Property="Validation.HasError" Value="true"> <Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}"/> <Setter Property="Background" Value="Red"/> </Trigger> </Style.Triggers> </Style> The problem is that my binding to Validation.Errors contains no data. How do I get this data from the Presenter class and pass it to this XAML so as to update the UI elements? EDIT: Textbox: <TextBox Style="{StaticResource textBoxInError}" Name="txtAge" Height="23" Grid.Row="3" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Center" Width="150"> <TextBox.Text> <Binding Path="StrAge" Mode="TwoWay" ValidatesOnDataErrors="True" UpdateSourceTrigger="PropertyChanged"/> </TextBox.Text> The validation occurs, but the style to be applied when data is invalid is not happening.

    Read the article

  • Loading and binding a serialized view model to a WPF window?

    - by generalt
    Hello all. I'm writing a one-window UI for a simple ETL tool. The UI consists of the window, the code behind for the window, a view model for the window, and the business logic. I wanted to provide functionality to the users to save the state of the UI because the content of about 10-12 text boxes will be reused between sessions, but are specific to the user. I figured I could serialize the view model, which contains all the data from the textboxes, and this works fine, but I'm having trouble loading the information in the serialized XML file back into the text boxes. Constructor of window: public ETLWindow() { InitializeComponent(); _viewModel = new ViewModel(); this.DataContext = _viewModel; _viewModel.State = Constants.STATE_IDLE; Loaded += new RoutedEventHandler(MainWindow_Loaded); } XAML: <TextBox x:Name="targetDirectory" IsReadOnly="true" Text="{Binding TargetDatabaseDirectory, UpdateSourceTrigger=PropertyChanged}"/> ViewModel corresponding property: private string _targetDatabaseDirectory; [XmlElement()] public string TargetDatabaseDirectory { get { return _targetDatabaseDirectory; } set { _targetDatabaseDirectory = value; OnPropertyChanged(DataUtilities.General.Utilities.GetPropertyName(() => new ViewModel().TargetDatabaseDirectory)); } Load event in code behind: private void loadState_Click(object sender, RoutedEventArgs e) { string statePath = this.getFilePath(); _viewModel = ViewModel.LoadModel(statePath); } As you can guess, the LoadModel method deserializes the serialized file on the user's drive. I couldn't find much on the web regarding this issue. I know this probably has something to do with my bindings. Is there some way to refresh on the bindings on the XAML after I deserialize the view model? Or perhaps refresh all properties on the view model? Or am I completely insane thinking any of this could be done? Thanks.

    Read the article

  • How do I change the CellErrorStyle for an Xceed Datagrid?

    - by Bob
    So in the Xceed documentation there is a code example that does not work for me. It may be because my grid is bound to a DataGridCollectionView. The objects in the collection used by the datagridcollection are what implement IDataErrorInfo. The errors are showing up just fine. The problem is that they are using the default orange background for errors...I need a red border. Below is the XAML instantiation of my grid. I set the DataCell background property to red just so I could be sure I had access to the grid's properties... I do. I just can't find the way to identify the cell's w/ errors so I can style them. Thanks! <XceedDG:DataGridControl Grid.Row="1" Grid.ColumnSpan="5" ItemsSource="{Binding Path = ABGDataGridCollectionView, UpdateSourceTrigger=PropertyChanged}" Background="{x:Static Views:DataGridControlBackgroundBrushes.ElementalBlue}" IsDeleteCommandEnabled="True" FontSize="16" AutoCreateColumns="False" x:Name="EncounterDataGrid" AllowDrop="True"> <XceedDG:DataGridControl.View> <Views:TableView ColumnStretchMode="All" ShowRowSelectorPane="True" ColumnStretchMinWidth="100"> <Views:TableView.FixedHeaders> <DataTemplate> <XceedDG:InsertionRow Height="40"/> </DataTemplate> </Views:TableView.FixedHeaders> </Views:TableView> </XceedDG:DataGridControl.View> <!--Group Header formatting--> <XceedDG:DataGridControl.Resources> <Style TargetType="{x:Type XceedDG:GroupByControl}"> <Setter Property="Visibility" Value="Collapsed"/> </Style> <Style TargetType="{x:Type XceedDG:DataCell}"> <Setter Property="Background" Value="Red"/> </Style> </XceedDG:DataGridControl.Resources> ...

    Read the article

  • WPF ValidationRule Validate when the control is loaded

    - by PaN1C_Showt1Me
    Hi ! I have a control with this validation <MyPicker.SelectedItem> <Binding Path="Person.Value" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" NotifyOnValidationError="True"> <Binding.ValidationRules> <rules:MyValidationRule ValidationType="notnull"/> </Binding.ValidationRules> </Binding> </MyPicker.SelectedItem> This is the Validation Class: class MyValidationRule : ValidationRule { private string _validationType; public string ValidationType { get { return _validationType; } set { _validationType = value; } } public override ValidationResult Validate(object value, CultureInfo cultureInfo) { ValidationResult trueResult = new ValidationResult(true, null); switch (_validationType.ToLower()) { case "notnull": return value == null ? new ValidationResult(false, "EMPTY FIELD") : trueResult; default: return trueResult; } } } Question: When the property is changed, then the Validate( ) method is called which is correct. But to call this method at the very beginning when the MyControl is created? I need to prove immediate after initialize if the there's a null value in the control (and display a validation error)

    Read the article

  • Show me your Linq to SQL architectures!

    - by Brad Heller
    I've been using Linq to SQL for a new implementation that I've been working on. I have about 5000 lines of code and am a little ways from a solid demo. I've been pretty satisfied with Linq to SQL so far -- the tools are excellent and pretty painless and it allows you to get a DAL up and running quickly. That said, there are some major draw backs that I just keep hitting over and over again. Namely how to handle separation of concerns between my DAL and my business layer and juggling that with different data contexts. Here is the architecture I've been using: My repositories do all my data access and they return Linq to SQL objects. Each of my Linq to SQL objects implements an IDetachable interface. A typical implementation looks like this: partial class PaymentDetail : IDetachable { #region IDetachable Members public bool IsAttached { get { return PropertyChanging != null; } } public void Detach() { if (IsAttached) { PropertyChanged = null; PropertyChanging = null; Transaction.Detach(); } } #endregion } Every time I do a DAL operation in my repository I "detach" when I'm done with the object (and it should theoretically detach from any child objects) to remove the DataContext's context. Like I said, this works pretty well, but there are some edge cases that seem to be a big pain in the ass. For instance, my Transaction object has many PaymentDetails. Even when there are no PaymentDetails in that collection it's still attached to the DataContext's context! Thus, if I try to update (I update by Attach()ing to the object and then SubmitChanges()) I get that dreaded "An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext. This is not supported." message. Anyway, I'm starting to doubt that this technology was a good gamble. Has anyone got a decent architecture that they're willing to share? I'd really love to use this technology but I feel like I spend 1/3 of my time just debugging is retarded quirks!

    Read the article

  • Databinding combobox selected item to settings

    - by Tuukka
    I store user specified settings using application settings properties and databinding. It has been working fine, until i want user selected to font for combobox. Databinding between user settings and combobox not working. I want to store font family name. App.XML <Application.Resources> <ResourceDictionary> <properties:Settings x:Key="Settings" /> </ResourceDictionary> </Application.Resources> Window.XML <ComboBox Name="Families" ItemsSource="{x:Static Fonts.SystemFontFamilies}" <!-- This line --> SelectedItem="{Binding Source={StaticResource Settings}, Path=Default.Font, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Margin="57,122,199,118"> <ComboBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding}" FontFamily="{Binding}"/> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> Settings: font String User Arial

    Read the article

  • Setting up a pc bluetooth server for android

    - by Del
    Alright, I've been reading a lot of topics the past two or three days and nothing seems to have asked this. I am writing a PC side server for my andriod device, this is for exchanging some information and general debugging. Eventually I will be connecting to a SPP device to control a microcontroller. I have managed, using the following (Android to pc) to connect to rfcomm channel 11 and exchange data between my android device and my pc. Method m = device.getClass().getMethod("createRfcommSocket", new Class[] { int.class }); tmp = (BluetoothSocket) m.invoke(device, Integer.valueOf(11)); I have attempted the createRfcommSocketToServiceRecord(UUID) method, with absolutely no luck. For the PC side, I have been using the C Bluez stack for linux. I have the following code which registers the service and opens a server socket: int main(int argc, char **argv) { struct sockaddr_rc loc_addr = { 0 }, rem_addr = { 0 }; char buf[1024] = { 0 }; char str[1024] = { 0 }; int s, client, bytes_read; sdp_session_t *session; socklen_t opt = sizeof(rem_addr); session = register_service(); s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); loc_addr.rc_family = AF_BLUETOOTH; loc_addr.rc_bdaddr = *BDADDR_ANY; loc_addr.rc_channel = (uint8_t) 11; bind(s, (struct sockaddr *)&loc_addr, sizeof(loc_addr)); listen(s, 1); client = accept(s, (struct sockaddr *)&rem_addr, &opt); ba2str( &rem_addr.rc_bdaddr, buf ); fprintf(stderr, "accepted connection from %s\n", buf); memset(buf, 0, sizeof(buf)); bytes_read = read(client, buf, sizeof(buf)); if( bytes_read 0 ) { printf("received [%s]\n", buf); } sprintf(str,"to Android."); printf("sent [%s]\n",str); write(client, str, sizeof(str)); close(client); close(s); sdp_close( session ); return 0; } sdp_session_t *register_service() { uint32_t svc_uuid_int[] = { 0x00000000,0x00000000,0x00000000,0x00000000 }; uint8_t rfcomm_channel = 11; const char *service_name = "Remote Host"; const char *service_dsc = "What the remote should be connecting to."; const char *service_prov = "Your mother"; uuid_t root_uuid, l2cap_uuid, rfcomm_uuid, svc_uuid; sdp_list_t *l2cap_list = 0, *rfcomm_list = 0, *root_list = 0, *proto_list = 0, *access_proto_list = 0; sdp_data_t *channel = 0, *psm = 0; sdp_record_t *record = sdp_record_alloc(); // set the general service ID sdp_uuid128_create( &svc_uuid, &svc_uuid_int ); sdp_set_service_id( record, svc_uuid ); // make the service record publicly browsable sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP); root_list = sdp_list_append(0, &root_uuid); sdp_set_browse_groups( record, root_list ); // set l2cap information sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID); l2cap_list = sdp_list_append( 0, &l2cap_uuid ); proto_list = sdp_list_append( 0, l2cap_list ); // set rfcomm information sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID); channel = sdp_data_alloc(SDP_UINT8, &rfcomm_channel); rfcomm_list = sdp_list_append( 0, &rfcomm_uuid ); sdp_list_append( rfcomm_list, channel ); sdp_list_append( proto_list, rfcomm_list ); // attach protocol information to service record access_proto_list = sdp_list_append( 0, proto_list ); sdp_set_access_protos( record, access_proto_list ); // set the name, provider, and description sdp_set_info_attr(record, service_name, service_prov, service_dsc); int err = 0; sdp_session_t *session = 0; // connect to the local SDP server, register the service record, and // disconnect session = sdp_connect( BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY ); err = sdp_record_register(session, record, 0); // cleanup //sdp_data_free( channel ); sdp_list_free( l2cap_list, 0 ); sdp_list_free( rfcomm_list, 0 ); sdp_list_free( root_list, 0 ); sdp_list_free( access_proto_list, 0 ); return session; } And another piece of code, in addition to 'sdptool browse local' which can verifty that the service record is running on the pc: int main(int argc, char **argv) { uuid_t svc_uuid; uint32_t svc_uuid_int[] = { 0x00000000,0x00000000,0x00000000,0x00000000 }; int err; bdaddr_t target; sdp_list_t *response_list = NULL, *search_list, *attrid_list; sdp_session_t *session = 0; str2ba( "01:23:45:67:89:AB", &target ); // connect to the SDP server running on the remote machine session = sdp_connect( BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY ); // specify the UUID of the application we're searching for sdp_uuid128_create( &svc_uuid, &svc_uuid_int ); search_list = sdp_list_append( NULL, &svc_uuid ); // specify that we want a list of all the matching applications' attributes uint32_t range = 0x0000ffff; attrid_list = sdp_list_append( NULL, &range ); // get a list of service records that have UUID 0xabcd err = sdp_service_search_attr_req( session, search_list, \ SDP_ATTR_REQ_RANGE, attrid_list, &response_list); sdp_list_t *r = response_list; // go through each of the service records for (; r; r = r-next ) { sdp_record_t *rec = (sdp_record_t*) r-data; sdp_list_t *proto_list; // get a list of the protocol sequences if( sdp_get_access_protos( rec, &proto_list ) == 0 ) { sdp_list_t *p = proto_list; // go through each protocol sequence for( ; p ; p = p-next ) { sdp_list_t *pds = (sdp_list_t*)p-data; // go through each protocol list of the protocol sequence for( ; pds ; pds = pds-next ) { // check the protocol attributes sdp_data_t *d = (sdp_data_t*)pds-data; int proto = 0; for( ; d; d = d-next ) { switch( d-dtd ) { case SDP_UUID16: case SDP_UUID32: case SDP_UUID128: proto = sdp_uuid_to_proto( &d-val.uuid ); break; case SDP_UINT8: if( proto == RFCOMM_UUID ) { printf("rfcomm channel: %d\n",d-val.int8); } break; } } } sdp_list_free( (sdp_list_t*)p-data, 0 ); } sdp_list_free( proto_list, 0 ); } printf("found service record 0x%x\n", rec-handle); sdp_record_free( rec ); } sdp_close(session); } Output: $ ./search rfcomm channel: 11 found service record 0x10008 sdptool: Service Name: Remote Host Service Description: What the remote should be connecting to. Service Provider: Your mother Service RecHandle: 0x10008 Protocol Descriptor List: "L2CAP" (0x0100) "RFCOMM" (0x0003) Channel: 11 And for logcat I'm getting this: 07-22 15:57:06.087: ERROR/BTLD(215): ****************search UUID = 0000*********** 07-22 15:57:06.087: INFO//system/bin/btld(209): btapp_dm_GetRemoteServiceChannel() 07-22 15:57:06.087: INFO//system/bin/btld(209): ##### USerial_Ioctl: BT_Wake, 0x8003 #### 07-22 15:57:06.097: INFO/ActivityManager(88): Displayed activity com.example.socktest/.socktest: 79 ms (total 79 ms) 07-22 15:57:06.697: INFO//system/bin/btld(209): ##### USerial_Ioctl: BT_Sleep, 0x8004 #### 07-22 15:57:07.517: WARN/BTLD(215): ccb timer ticks: 2147483648 07-22 15:57:07.517: INFO//system/bin/btld(209): ##### USerial_Ioctl: BT_Wake, 0x8003 #### 07-22 15:57:07.547: WARN/BTLD(215): info:x10 07-22 15:57:07.547: INFO/BTL-IFS(215): send_ctrl_msg: [BTL_IFS CTRL] send BTLIF_DTUN_SIGNAL_EVT (CTRL) 10 pbytes (hdl 14) 07-22 15:57:07.547: DEBUG/DTUN_HCID_BZ4(253): dtun_dm_sig_link_up() 07-22 15:57:07.547: INFO/DTUN_HCID_BZ4(253): dtun_dm_sig_link_up: dummy_handle = 342 07-22 15:57:07.547: DEBUG/ADAPTER(253): adapter_get_device(00:02:72:AB:7C:EE) 07-22 15:57:07.547: ERROR/BluetoothEventLoop.cpp(88): pollData[0] is revented, check next one 07-22 15:57:07.547: ERROR/BluetoothEventLoop.cpp(88): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/253/hci0/dev_00_02_72_AB_7C_EE 07-22 15:57:07.777: WARN/BTLD(215): process_service_search_attr_rsp 07-22 15:57:07.787: INFO/BTL-IFS(215): send_ctrl_msg: [BTL_IFS CTRL] send BTLIF_DTUN_SIGNAL_EVT (CTRL) 13 pbytes (hdl 14) 07-22 15:57:07.787: INFO/DTUN_HCID_BZ4(253): dtun_dm_sig_rmt_service_channel: success=0, service=00000000 07-22 15:57:07.787: ERROR/DTUN_HCID_BZ4(253): discovery unsuccessful! 07-22 15:57:08.497: INFO//system/bin/btld(209): ##### USerial_Ioctl: BT_Sleep, 0x8004 #### 07-22 15:57:09.507: INFO//system/bin/btld(209): ##### USerial_Ioctl: BT_Wake, 0x8003 #### 07-22 15:57:09.597: INFO/BTL-IFS(215): send_ctrl_msg: [BTL_IFS CTRL] send BTLIF_DTUN_SIGNAL_EVT (CTRL) 11 pbytes (hdl 14) 07-22 15:57:09.597: DEBUG/DTUN_HCID_BZ4(253): dtun_dm_sig_link_down() 07-22 15:57:09.597: INFO/DTUN_HCID_BZ4(253): dtun_dm_sig_link_down device = 0xf7a0 handle = 342 reason = 22 07-22 15:57:09.597: ERROR/BluetoothEventLoop.cpp(88): pollData[0] is revented, check next one 07-22 15:57:09.597: ERROR/BluetoothEventLoop.cpp(88): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/253/hci0/dev_00_02_72_AB_7C_EE 07-22 15:57:09.597: DEBUG/BluetoothA2dpService(88): Received intent Intent { act=android.bluetooth.device.action.ACL_DISCONNECTED (has extras) } 07-22 15:57:10.107: INFO//system/bin/btld(209): ##### USerial_Ioctl: BT_Sleep, 0x8004 #### 07-22 15:57:12.107: DEBUG/BluetoothService(88): Cleaning up failed UUID channel lookup: 00:02:72:AB:7C:EE 00000000-0000-0000-0000-000000000000 07-22 15:57:12.107: ERROR/Socket Test(5234): connect() failed 07-22 15:57:12.107: DEBUG/ASOCKWRP(5234): asocket_abort [31,32,33] 07-22 15:57:12.107: INFO/BLZ20_WRAPPER(5234): blz20_wrp_shutdown: s 31, how 2 07-22 15:57:12.107: DEBUG/BLZ20_WRAPPER(5234): blz20_wrp_shutdown: fd (-1:31), bta -1, rc 0, wflags 0x0 07-22 15:57:12.107: INFO/BLZ20_WRAPPER(5234): __close_prot_rfcomm: fd 31 07-22 15:57:12.107: INFO/BLZ20_WRAPPER(5234): __close_prot_rfcomm: bind not completed on this socket 07-22 15:57:12.107: DEBUG/BLZ20_WRAPPER(5234): btlif_signal_event: fd (-1:31), bta -1, rc 0, wflags 0x0 07-22 15:57:12.107: DEBUG/BLZ20_WRAPPER(5234): btlif_signal_event: event BTLIF_BTS_EVT_ABORT matched 07-22 15:57:12.107: DEBUG/BTL_IFC_WRP(5234): wrp_close_s_only: wrp_close_s_only [31] (31:-1) [] 07-22 15:57:12.107: DEBUG/BTL_IFC_WRP(5234): wrp_close_s_only: data socket closed 07-22 15:57:12.107: DEBUG/BTL_IFC_WRP(5234): wsactive_del: delete wsock 31 from active list [ad3e1494] 07-22 15:57:12.107: DEBUG/BTL_IFC_WRP(5234): wrp_close_s_only: wsock fully closed, return to pool 07-22 15:57:12.107: DEBUG/BLZ20_WRAPPER(5234): btsk_free: success 07-22 15:57:12.107: DEBUG/BLZ20_WRAPPER(5234): blz20_wrp_write: wrote 1 bytes out of 1 on fd 33 07-22 15:57:12.107: DEBUG/ASOCKWRP(5234): asocket_destroy 07-22 15:57:12.107: DEBUG/ASOCKWRP(5234): asocket_abort [31,32,33] 07-22 15:57:12.107: INFO/BLZ20_WRAPPER(5234): blz20_wrp_shutdown: s 31, how 2 07-22 15:57:12.107: DEBUG/BLZ20_WRAPPER(5234): blz20_wrp_shutdown: btsk not found, normal close (31) 07-22 15:57:12.107: DEBUG/BLZ20_WRAPPER(5234): blz20_wrp_write: wrote 1 bytes out of 1 on fd 33 07-22 15:57:12.107: INFO/BLZ20_WRAPPER(5234): blz20_wrp_close: s 33 07-22 15:57:12.107: DEBUG/BLZ20_WRAPPER(5234): blz20_wrp_close: btsk not found, normal close (33) 07-22 15:57:12.107: INFO/BLZ20_WRAPPER(5234): blz20_wrp_close: s 32 07-22 15:57:12.107: DEBUG/BLZ20_WRAPPER(5234): blz20_wrp_close: btsk not found, normal close (32) 07-22 15:57:12.107: INFO/BLZ20_WRAPPER(5234): blz20_wrp_close: s 31 07-22 15:57:12.107: DEBUG/BLZ20_WRAPPER(5234): blz20_wrp_close: btsk not found, normal close (31) 07-22 15:57:12.157: DEBUG/Sensors(88): close_akm, fd=151 07-22 15:57:12.167: ERROR/CachedBluetoothDevice(477): onUuidChanged: Time since last connect14970690 07-22 15:57:12.237: DEBUG/Socket Test(5234): -On Stop- Sorry for bombarding you guys with what seems like a difficult question and a lot to read, but I've been working on this problem for a while and I've tried a lot of different things to get this working. Let me reiterate, I can get it to work, but not using service discovery protocol. I've tried a several different UUIDs and on two different computers, although I only have my HTC Incredible to test with. I've also heard some rumors that the BT stack wasn't working on the HTC Droid, but that isn't the case, at least, for PC interaction.

    Read the article

  • How do I properly implement a property in F#?

    - by Greg D
    Consider my first attempt, a simple type in F# like the following: type Test() = inherit BaseImplementingNotifyPropertyChangedViaOnPropertyChanged() let mutable prop: string = null member this.Prop with public get() = prop and public set value = match value with | _ when value = prop -> () | _ -> let prop = value this.OnPropertyChanged("Prop") Now I test this via C# (this object is being exposed to a C# project, so apparent C# semantics are desirable): [TestMethod] public void TaskMaster_Test() { var target = new FTest(); string propName = null; target.PropertyChanged += (s, a) => propName = a.PropertyName; target.Prop = "newString"; Assert.AreEqual("Prop", propName); Assert.AreEqual("newString", target.Prop); return; } propName is properly assigned, my F# Setter is running, but the second assert is failing because the underlying value of prop isn't changed. This sort of makes sense to me, because if I remove mutable from the prop field, no error is generated (and one should be because I'm trying to mutate the value). I think I must be missing a fundamental concept. What's the correct way to rebind/mutate prop in the Test class so that I can pass my unit test?

    Read the article

  • Is there an MVVM-friendly way to swap views without value converters firing unnecessarily?

    - by DanM
    I thought what I was doing was right out of the Josh Smith MVVM handbook, but I seem to be having a lot of problems with value converters firing when no data in the view-model has changed. So, I have a ContentControl defined in XAML like this: <ContentControl Grid.Row="0" Content="{Binding CurrentViewModel}" /> The Window containing this ContentControl references a resource dictionary that looks something like this: <ResourceDictionary ...> <DataTemplate DataType="{x:Type lib_vm:SetupPanelViewModel}"> <lib_v:SetupPanel /> </DataTemplate> <DataTemplate DataType="{x:Type lib_vm:InstructionsPanelViewModel}"> <lib_v:InstructionsPanel /> </DataTemplate> </ResourceDictionary> So, basically, the two data templates specify which view to show with which view-model. This switches the views as expected whenever the CurrentViewModel property on my window's view-model changes, but it also seems to cause value converters on the views to fire even when no data has changed. It's a particular problem with IMultiValueConverter classes, because the values in the value array get set to DependencyProperty.UnsetValue, which causes exceptions unless I specifically check for that. But I'm getting other weird side effects too. This has me wondering if I shouldn't just do everything manually, like this: Instantiate each view. Set the DataContext of each view to the appropriate view-model. Give the ContentControl a name and make it public. Handle the PropertyChanged event for the window. In the event handler, manually set the Content property of the ContentControl to the appropriate view, based the CurrentViewModel (using if statements). This seems to work, but it also seems very inelegant. I'm hoping there's a better way. Could you please advise me the best way to handle view switching so that value converters don't fire unnecessarily?

    Read the article

  • How do I stop ValueConverters from firing when swapping the content of a ContentControl

    - by DanM
    I thought what I was doing was right out of the Josh Smith MVVM handbook, but I seem to be having a lot of problems with value converters firing when no data in the view-model has changed. So, I have a ContentControl defined in XAML like this: <ContentControl Grid.Row="0" Content="{Binding CurrentViewModel}" /> The Window containing this ContentControl references a resource dictionary that looks something like this: <ResourceDictionary ...> <DataTemplate DataType="{x:Type lib_vm:SetupPanelViewModel}"> <lib_v:SetupPanel /> </DataTemplate> <DataTemplate DataType="{x:Type lib_vm:InstructionsPanelViewModel}"> <lib_v:InstructionsPanel /> </DataTemplate> </ResourceDictionary> So, basically, the two data templates specify which view to show with which view-model. This switches the views as expected whenever the CurrentViewModel property on my window's view-model changes, but it also seems to cause value converters on the views to fire even when no data has changed. It's a particular problem with IMultiValueConverter classes, because the values in the value array get set to DependencyProperty.UnsetValue, which causes exceptions unless I specifically check for that. But I'm getting other weird side effects too. This has me wondering if I shouldn't just do everything manually, like this: Instantiate each view. Set the DataContext of each view to the appropriate view-model. Give the ContentControl a name and make it public. Handle the PropertyChanged event for the window. In the event handler, manually set the Content property of the ContentControl to the appropriate view, based the CurrentViewModel (using if statements). This seems to work, but it also seems very inelegant. I'm hoping there's a better way. Could you please advise me the best way to handle view switching so that value converters don't fire unnecessarily?

    Read the article

  • wpf error template - red box still visible on collapse of an expander

    - by Andy Clarke
    Hi, I'm doing some validation on the DataSource of TextBox that's within an Expander and have found that once a validation error has been triggered, if I collapse the Expander, the red box stays where the TextBox would have been. <Expander Header="Blah Blah Blah"> <TextBox Name="TextBox" Validation.ErrorTemplate="{DynamicResource TextBoxErrorTemplate}" Text="{Binding Path=Blah, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" /> </Expander> I've tried to get round this by binding the visibility of the Error Template to the Expander, however I think there's something wrong with the binding. <local:NotVisibleConverter x:Key="NotVisibleConverter" /> <ControlTemplate x:Key="TextBoxErrorTemplate"> <DockPanel> <Border BorderBrush="Red" BorderThickness="2" Visibility="{Binding Path=IsExpanded, Converter={StaticResource NotVisibleConverter}, RelativeSource={RelativeSource AncestorType=Expander}}" > <AdornedElementPlaceholder Name="MyAdorner" /> </Border> </DockPanel> <ControlTemplate.Triggers> <Trigger Property="Validation.HasError" Value="true"> <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> I guess I've gone wrong with my binding, can someone put me back on track please? Alternatively does anyone know another solution to the ErrorTemplate still being visible on the collapse of an Expander?

    Read the article

  • WPF binding problem

    - by xine
    I've got some bindings in UI: <Window x:Class="Tester.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="377" Width="562" xmlns:my="clr-namespace:MyApp"> <Grid> <TextBlock Text="{Binding Path=current.Text}" Name="Text1" /> <TextBlock Text="{Binding Path=current.o.Text}" Name="Text2" /> </Grid> </Window> Code: class Coordinator : INotifyPropertyChanged{ List<Myclass1> list; int currId = 0; public Myclass1 current{ return list[currId]; } public int CurrId { get { return currId; } set { currId = value; this.PropertyChanged(this,new PropertyChangedEventArgs("current")); } } class Myclass1{ public string Text{get;} public Myclass2 o{get;} } class Myclass2{ public string Text{get;} } When currId changes Tex1 in UI changes too,but Text2 doesn't. I'm assuming this happens because Text2's source isn't updated. Does anyone know how to fix it?

    Read the article

  • .NET ValidationRule problem

    - by PaN1C_Showt1Me
    Hi ! I have a control with this validation <MyPicker.SelectedItem> <Binding Path="Person.Value" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" NotifyOnValidationError="True"> <Binding.ValidationRules> <rules:MyValidationRule ValidationType="notnull"/> </Binding.ValidationRules> </Binding> </MyPicker.SelectedItem> This is the Validation Class: class MyValidationRule : ValidationRule { private string _validationType; public string ValidationType { get { return _validationType; } set { _validationType = value; } } public override ValidationResult Validate(object value, CultureInfo cultureInfo) { ValidationResult trueResult = new ValidationResult(true, null); switch (_validationType.ToLower()) { case "notnull": return value == null ? new ValidationResult(false, "EMPTY FIELD") : trueResult; default: return trueResult; } } } Question: When the property is changed, then the Validate( ) method is called which is correct. But to call this method at the very beginning when the MyControl is created? I need to prove immediate after initialize if the there's a null value in the control (and display a validation error)

    Read the article

< Previous Page | 4 5 6 7 8 9 10  | Next Page >