|
Hi,
Thanks for fast reply .
I have an Hashtable that contains objects.
And I want to save it not matter what.
I will glad if you can explain to me what is the better way to do it(XML or file)?
Thanks again.
|
|
|
|
|
If the objects are all serializable, then it's a simple matter to serialize them to file using something like the XmlSerializer .
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi,
Thanks again.
1)Can I serialize only the Hashtable?
Or I need to serialize every object one by one?
2)I have one Hashtable that its objects don't serializable,
Is there any way to cache it?
Thanks a lot.
|
|
|
|
|
Serializing the hash table should serialize the component objects. Remember that they need to be serializable objects in their own right for this to work.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Thanks,
I have linq to sql objects and I found that I can serialize the sql by putting
this: < Database ... Serialization="Unidirectional > on the dbml file.
How can I serialize Hashtable that contain objects like that?
Thanks a lot.
modified on Monday, August 23, 2010 2:43 AM
|
|
|
|
|
Why would you want to? This indicates that the data is already saved to the database - meaning you don't need to save it to a different storage medium.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I have sql query and I want to save every running the row that selected from each table.
I found solution for that .
I mark the dmbl as serializable with
<Database... Serialization="Unidirectional">
and than use NetDataContractSerializer object to serialize\deserialize.
Now, I have another problem, I want to save also the search criterions,
every search I save the controls with the search criterions in hashtable,
and I want to save it also at xml but the controls are not serializable(I use wpf and telerik controls).
Is thare any way to do it?
Thanks again.
|
|
|
|
|
I just want to get the text in elements like the id, name, and lastactive from an xml file like this ( http://www.dreamincode.net/forums/xml.php?showuser=34 ) into a textbox or anything that would just display in a simple way, but I haven't been able to find anything that explains that level of it. How can I do this?
-- Modified Sunday, August 22, 2010 3:07 AM
|
|
|
|
|
I demonstrate how to bind to XML data in this[^] article. All you need to do is replace the XmlDataProvider with a link to your data.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Never mind, figured it out. Thank you very much, your article and method was the first -after hours trying to get this to work- that made much sense to me.
-- Modified Sunday, August 22, 2010 5:39 AM
|
|
|
|
|
Sonar87 wrote: figured it ou
Excellent.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Is there any way I can get the resource/xml file I'm reading from to be changed, say, based on user input when the program is running, or does it have to stay a set path that I decide ahead of time? I tried accessing some of the info back in the Window1.xaml.cs file to to see if I could make changes there but if theres a way its nothing I've thought of.
|
|
|
|
|
You can change it just by changing the DataContext. As long as you've implemented your binding, your UI elements should change when the context does.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Dear All,
In Silverlight the openfiledialog is not remembered the last working (Selected) folder.
Also there is no initialdirectory is available in silverlight.
How could i achive the same. My problem is it has to remember the last folder.
Thanks.
|
|
|
|
|
You could always save the selected folder to isolated storage and use that if it's present.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi Experts,
I have a combo box inside a user control and i am trying to update an observable collection with the change event of this combo box. This combo box has a list view inside it. I have added a working example of this scenario so you can copy paste it in your VS IDE. The user control in this example is just a part of the original user control. I have removed the code which are not required.
--Customer.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
namespace TestMVVM
{
class Customer : INotifyPropertyChanged
{
public int ID { get; set; }
public int NumberOfContracts { get; set; }
private string firstName;
private string lastName;
public string FirstName
{
get { return firstName; }
set
{
if (firstName != value)
{
firstName = value;
RaisePropertyChanged("FirstName");
}
}
}
public string LastName
{
get { return lastName; }
set
{
if (lastName != value)
{
lastName = value;
RaisePropertyChanged("LastName");
}
}
}
#region PropertChanged Block
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(string property)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
}
#endregion
}
}
--CustomerHeaderViewModel class
class CustomerHeaderViewModel
{
public ObservableCollection<Customer> Customers { get; set; }
public void LoadCustomers()
{
ObservableCollection<Customer> customers = new ObservableCollection<Customer>();
customers.Add(new Customer { ID = 1, FirstName = "Jim", LastName = "Smith", NumberOfContracts = 23 });
Customers = customers;
}
}
-- UCComboBox.xaml User Control
<UserControl x:Class="TestMVVM.UCComboBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="25" Width="200">
<Grid>
<ComboBox Height="23" HorizontalAlignment="Left" Margin="0,0,0,0" Name="cmbComboBoxControl"
VerticalAlignment="Top" Width="195"
IsEditable="True"/>
</Grid>
</UserControl>
-- UCComboBox.xaml.cs CodeBehind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.ComponentModel;
using System.Windows.Controls.Primitives;
namespace TestMVVM
{
public partial class UCComboBox : UserControl
{
public static readonly DependencyProperty ComboValueProperty =
DependencyProperty.Register("ComboValue", typeof(string), typeof(UCComboBox));
ListView _lstvMyView;
private string _valueColumn = "Id";
private string _displayColumn = "Display";
private DataTable _dataSource = null;
public UCComboBox()
{
InitializeComponent();
}
private string _comboValue;
public string ComboValue
{
get
{
return (string)GetValue(ComboValueProperty);
}
set
{
DataRow dr = null;
_comboValue = value;
SetValue(ComboValueProperty, value);
if (_comboValue != "")
{
if (_dataSource != null && _dataSource.Rows.Count > 0)
{
for (int i = 0; i < _dataSource.Rows.Count; i++)
{
if (_dataSource.Rows[i][_valueColumn].ToString() == value)
{
dr = _dataSource.Rows[i];
break;
}
}
if (dr == null)
{
cmbComboBoxControl.Text = "";
}
else
{
cmbComboBoxControl.Text = dr[_displayColumn].ToString();
}
}
}
}
}
public void LoadFromResultSet(DataTable dt)
{
_dataSource = dt;
CreateListView(dt);
cmbComboBoxControl.Items.Clear();
cmbComboBoxControl.Items.Add(_lstvMyView);
}
private void CreateListView(DataTable dt)
{
DataTable ListViewdt = dt;
_lstvMyView = new ListView();
Binding binding = new Binding();
binding.Source = ListViewdt.DefaultView;
_lstvMyView.SetBinding(ListView.ItemsSourceProperty, binding);
GridView grid = new GridView();
GridViewColumn gridcol = new GridViewColumn();
gridcol.Width = cmbComboBoxControl.Width;
gridcol.DisplayMemberBinding = new Binding(_displayColumn);
grid.Columns.Add(gridcol);
Style style = new Style(typeof(GridViewColumnHeader));
style.Setters.Add(new Setter { Property = GridViewColumnHeader.VisibilityProperty, Value = Visibility.Collapsed});
grid.ColumnHeaderContainerStyle = style;
_lstvMyView.View = grid;
_lstvMyView.SelectionChanged += new SelectionChangedEventHandler(lstvMyView_SelectionChanged);
}
private void lstvMyView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (_lstvMyView.ItemsSource != null)
{
DataRowView drv = (_lstvMyView.SelectedValue as DataRowView);
if (drv != null)
{
ComboValue = drv.Row[_valueColumn].ToString();
}
cmbComboBoxControl.IsDropDownOpen = false;
}
}
}
}
-- Window2.xaml
<Window x:Class="TestMVVM.Window2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestMVVM"
Title="Window2" Height="300" Width="300" Loaded="Window_Loaded">
<Grid>
<local:UCComboBox x:Name="cmbUC" />
<Button Height="23" HorizontalAlignment="Left" Margin="39,0,0,82"
Name="btnUpdate" VerticalAlignment="Bottom" Width="75" Click="btnUpdate_Click">Update</Button>
<Button Height="23" Margin="120,0,83,82" Name="btnChange" VerticalAlignment="Bottom" Click="btnChange_Click">Change</Button>
</Grid>
</Window>
-- Window2.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;
using System.Collections.ObjectModel;
namespace TestMVVM
{
public partial class Window2 : Window
{
CustomerHeaderViewModel customerHeaderViewModel = null;
public Window2()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
CreateDataTableParent();
cmbUC.LoadFromResultSet(dtableparent);
customerHeaderViewModel = new CustomerHeaderViewModel();
customerHeaderViewModel.LoadCustomers();
cmbUC.ComboValue = customerHeaderViewModel.Customers[0].ID.ToString();
}
DataTable dtableparent;
private void CreateDataTableParent()
{
dtableparent = new DataTable("Rock");
DataRow drow;
dtableparent.Columns.Add("Id", typeof(System.String));
dtableparent.Columns.Add("Display", typeof(System.String));
drow = dtableparent.NewRow();
drow["Id"] = "1";
drow["Display"] = "aaaa";
dtableparent.Rows.Add(drow);
drow = dtableparent.NewRow();
drow["Id"] = "2";
drow["Display"] = "bbbb";
dtableparent.Rows.Add(drow);
drow = dtableparent.NewRow();
drow["Id"] = "3";
drow["Display"] = "cccc";
dtableparent.Rows.Add(drow);
drow = dtableparent.NewRow();
drow["Id"] = "4";
drow["Display"] = "dddd";
dtableparent.Rows.Add(drow);
}
private void btnChange_Click(object sender, RoutedEventArgs e)
{
cmbUC.ComboValue = "2";
}
private void btnUpdate_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(customerHeaderViewModel.Customers[0].ID.ToString());
}
}
}
My question here is when i click on Change button the combo value changes but when i click on update button the value still remains the same. The same happens when i change the combo value through the UI. How can i make the observable collection update itself on change of the ComboValue property of the user control?
Please help!
Thanks in advance!
Regards,
Samar
|
|
|
|
|
Hi Samar,
From the first look of your query I will suggest you to use "DataBinding " for the ComboBox. As you are using ObservableCollection , you don't have to explicitly fire the refresh event. Once data changed in collection it will refresh implicitly. Next thing is, use Mode=TwoWay while binding to the properties inside your combobox. Use a DataTemplate to create your specific template. It will be easy for you to bind the values.
Have a look & get back to me if any issues.
Don't forget to Click on [Vote] and [Good Answer] on the posts that helped you.
Regards - Kunal Chowdhury | Software Developer | Chennai | India | My Blog | My Tweets | Silverlight Tutorial
|
|
|
|
|
Hi,
I am trying to do data binding in WPF using controls and indicators in "two" windows.
Window 1 has controls and indicators. The controls are source to properties in Window 2. When a property changes in Window 2, that property is sent back to an indicator in Window 1.
Setup:
Window 1 is comprised of normal .NET WPF objects in the form of controls and indicators. Window 2 however hosts an ActiveX control wrapped in a WindowsFormsHost object. Because of this I don't have access to the properties of the ActiveX control through XAML. So I have to use a dependency object in Window 2.
Anyone done anything like this? The norm (at least what I've found)is having all objects on one Window and having the ActiveX control complicates this. Maybe someone has the solution.
Thanks
|
|
|
|
|
Hi,
I have a problem using DataContractSerializer.
My Silverlight application asks for a web page that return an object serialized using DataContractSerializer.
When I try to deserialize the data, I obtain an empty object:
the object itself isn't null, but all the properties are set to "" for the strings or the arrays contain zero elements.
What can I do to solve this?
|
|
|
|
|
Hello everybody
I realy need help!
I have an custom multiscale image made with DeepZoom and I edit the source with Visual Studio 2010! The multiscale image it contains World map!
All I want to do is to add a custom PushPin into the map and when I move the map PushPin-s to save the position on the map!
Any ideas?
Thanks
|
|
|
|
|
|
I have the exact same problem
|
|
|
|
|
I can get all control on form in C# Windows Form App by "Control.ControlCollection coll = this.Controls"
Is there any simalar way in WPF to perform this task?
Any help would be appreciated
|
|
|
|
|
|
HI All,
DataTable data i binded to the comboBox, All values are coming correctly when i expand the combobox but after selection combobox item is coming as "System.Data.DataRowView". What's the problem. Please help me.
Sorry for my english.
Thanks in advance.
|
|
|
|