|
mm.. I worked around it with code like:
void UpdateValueSafe(decimal? newValue)
{
if (!IsLoaded)
return;
Value = newValue;
}
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
also, this.Coerce(ValueProperty) was the way to go!
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
I am working on this[] WPF application. Each time the user clicks Next I want to display the next view. Te areas in red will all have the header area at the top and the button area below.
From what I can see it's impossible to subclass an XAML view, but I think I can do it with a template. I just don't know how.
I'm open to suggestion.
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
It's not impossible to subclass XAML, it's fairly straightforward. In this case though, you simply need a ContentControl to host any one of a number of DataTemplates.
|
|
|
|
|
It's not impossible to subclass XAML, it's fairly straightforward.
Got an example of how to do this? I Googled it earlier and didn't see much.
In this case though, you simply need a ContentControl to host any one of a number of DataTemplates.
Actually, if I put a ContentPresenter in the center cell of the grid, then the Next/Previous functions could simply add/remove whatever control goes there at that point.
Everything makes sense in someone's mind
|
|
|
|
|
It looks like its just an inline wizard control. I'd go that route as that will help you keep your page logic seperated.
|
|
|
|
|
I think that you can do that using TabControl. Create tabcontrol template with invisible headers and navigate through it's Items when click Next or Prev. It will be like a wizard
|
|
|
|
|
Looks like a prime candidate for the Prism frameword (previously Composite Application Lib)
C# has already designed away most of the tedium of C++.
|
|
|
|
|
More of a request for clarification really. I am working on a Silverlight application using WCF RIA and MVVM and I am having a tough time understanding some of the deep abstraction I am seeing in examples. I am looking at the MS Bookshelf example and I really am lost to understand why there are so freaking many moving parts. See the following pieces:
Interface <abridged>:
public interface IBookDataService
{
event EventHandler<HasChangesEventArgs> NotifyHasChanges;
void Save(Action<SubmitOperation> submitCallback, object state);
void GetBooksByCategory(
Action<ObservableCollection<Book>> getBooksCallback,
int categoryID,
int pageSize);
void GetCategories(Action<ObservableCollection<Category>> getCategoriesCallback);
}
Class implementation of interface:
public class BookDataService : IBookDataService
{
private LoadOperation<Book> _booksLoadOperation;
private LoadOperation<Category> _categoriesLoadOperation;
private Action<ObservableCollection<Book>> _getBooksCallback;
private Action<ObservableCollection<Category>> _getCategoriesCallback;
private int _pageIndex = 0;
private BookClubContext Context { get; set; }
public event EventHandler<HasChangesEventArgs> NotifyHasChanges;
public BookDataService()
{
Context = new BookClubContext();
Context.PropertyChanged += ContextPropertyChanged;
}
private void ContextPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (NotifyHasChanges != null)
{
NotifyHasChanges(this, new HasChangesEventArgs(){HasChanges = Context.HasChanges});
}
}
public void Save(Action<SubmitOperation> submitCallback, object state)
{
if (Context.HasChanges)
{
Context.SubmitChanges(submitCallback, state);
}
}
public void GetBooksByCategory(
Action<ObservableCollection<Book>> getBooksCallback,
int categoryID,
int pageSize)
{
ClearBooks();
var query = Context.GetBooksByCategoryQuery(categoryID).Take(pageSize);
RunBooksQuery(query, getBooksCallback);
}
public void GetBooksByTitle(Action<ObservableCollection<Book>> getBooksCallback, int categoryID, string titleFilter)
{
ClearBooks();
var query = Context.GetBooksByCategoryQuery(categoryID)
.Where(b => b.Title.Contains(titleFilter));
RunBooksQuery(query, getBooksCallback);
}
private void ClearBooks()
{
_pageIndex = 0;
Context.Books.Clear();
}
private void RunBooksQuery(EntityQuery<Book> query, Action<ObservableCollection<Book>> getBooksCallback)
{
_getBooksCallback = getBooksCallback;
_booksLoadOperation = Context.Load<Book>(query);
_booksLoadOperation.Completed += OnLoadBooksCompleted;
}
private void OnLoadBooksCompleted(object sender, EventArgs e)
{
_booksLoadOperation.Completed -= OnLoadBooksCompleted;
var books = new EntityList<Book>(Context.Books, _booksLoadOperation.Entities);
_getBooksCallback(books);
}
public void GetCategories(Action<ObservableCollection<Category>> getCategoriesCallback)
{
_getCategoriesCallback = getCategoriesCallback;
Context.Categories.Clear();
_categoriesLoadOperation = Context.Load<Category>(Context.GetCategoriesQuery());
_categoriesLoadOperation.Completed += OnLoadCategoriesCompleted;
}
private void OnLoadCategoriesCompleted(object sender, EventArgs e)
{
_categoriesLoadOperation.Completed -= OnLoadCategoriesCompleted;
var categories = new EntityList<Category>(Context.Categories, _categoriesLoadOperation.Entities);
_getCategoriesCallback(categories);
}
}
And the viewmodel too:
public void LoadBooksByCategory()
{
Books = null;
if (SelectedCategory != null)
BookDataService.GetBooksByCategory(GetBooksCallback, SelectedCategory.CategoryID, _pageSize);
}
private void GetBooksCallback(ObservableCollection<Book> books)
{
if (books != null)
{
if (Books == null)
{
Books = books;
}
else
{
foreach (var book in books)
{
Books.Add(book);
}
}
if (Books.Count > 0)
{
SelectedBook = Books[0];
}
}
}
And there is the web side components as well. The thing is, it is a lot of code and I am trying to figure out why there is so much of it? Can someone just give me a quick breakdown of why there are so many callbacks? I have never been crystal clear on callbacks and delegates to begin with, so this is just a nightmarish mess.
Cheers, --EA
|
|
|
|
|
The reason there are callbacks here is because the operations are completed asynchronously, which means that there needs to be a mechanism to notify the SL application that an operation has completed and that it can act on it if necessary. The mechanism to do this is a callback. It really is that simple.
|
|
|
|
|
Let's say I have a State class that has a collection of Counties:
public class State
{
public State()
{
Counties = new ObservableCollection<County>();
}
public String StateName
{ get; set; }
public String NickName
{ get; set; }
public ObservableCollection<County> Counties
{ get; set; }
}
public class County
{
public County()
{
}
public String CountyName
{ get; set; }
public String Population
{ get; set; }
}
Now, let's say I have a View that has a ListView (I have used MVVM architecture, so the View is a UserControl).
The View has the DataContext set to a collection of States (this is actually done via a DataTemplate).
How do I use databinding to display a single row for each county? The sticking point for me is that I want to display the Name of the State on the same row as the CountyName and Population.
For instance, the ListView might have the following records:
State Name | County Name | Population
Alabama | Acounty | 20000
Alabama | Bcounty | 40000
Colorado | CntyNm | 10000
The code in the UserControl might look something like this...which doesn't work...
<ListView ItemsSource="{Binding}">
<ListView.View>
<GridView>
<GridViewColumn Header=" State Name " DisplayMemberBinding="{Binding StateName}" />
<GridViewColumn Header=" County Name" DisplayMemberBinding="{Binding Counties.CountyName}" />
<GridViewColumn Header=" Population " DisplayMemberBinding="{Binding Counties.Population}"/>
</GridView>
</ListView.View>
</ListView>
I have been able to bind to properties of the State, properties of the County, but not both. I want a single record, or row, in the ListView for each County in each State. I want to show the name of the State too. I'm really asking for this specifically. I'm not looking to use grouping since this doesn't work with what my client's needs. I've created this example with the hopes that States/Counties are easier to understand and would use grouping if this were the data I was actually working with.
|
|
|
|
|
Sounds to me like your heirarchy for this is "backwards"....
If I understand correctly, you need to effectively show a list of counties ordered by their state, but what you have is a list of states.
Perhaps if you used a County class with a State field, and just bound your list to an ObservableCollection<county> - would that fly in this instance? You could use linq to ensure that the collection comes out in State order.
C# has already designed away most of the tedium of C++.
|
|
|
|
|
Hmmm...I didn't think about doing it that way. Indeed that does work.
public class State
{
public State()
{
}
public String StateName
{ get; set; }
public String NickName
{ get; set; }
}
public class County
{
public County()
{
State = new State();
}
public String CountyName
{ get; set; }
public String Population
{ get; set; }
public State State
{ get; set; }
}
<ListView ItemsSource="{Binding}">
<ListView.View>
<GridView>
<GridViewColumn Header=" State Name " DisplayMemberBinding="{Binding State.StateName}"/>
<GridViewColumn Header=" County Name " DisplayMemberBinding="{Binding CountyName}"/>
<GridViewColumn Header=" Population " DisplayMemberBinding="{Binding Population}"/>
</GridView>
</ListView.View>
</ListView>
My only concern is that now I will replicate State objects in memory unnecessarily. Kinda seems like I'm changing my entities to suit the presentation of the data. Good idea though and certainly a possibility. Especially because the client requirements on this are fairly rigid. You've got my wheels turning again.
|
|
|
|
|
You are re-creating the State object for every County object which is *REALLY* bad and will come back to bite you down the road. Not because of memory concerns (well, that is an issue too), but the bigger problem is that you will screw up data binding.
Lets say you have 100 counties that have State = California. As you have it implemented, there will be 100 County objects and 100 State (California) objects. Now lets say your UI is binding to County.State.NickName for each of the 100 County objects. If you change NickName in one of the State (California) objects, it will not get reflected in the other 99 counties because those will all be considered different instances. I.e. your UI will be bound to 100 *different* State objects instead of the same one.
There are only 50 states, so what I think you want to do here is have a singleton "States" array that contains the 50 states and have the County just point to the one state object from that array... actually a dictionary might be more appropriate... so you could do something like:
public County()
{
State = States["CA"];
State = States["NY"];
}
etc.
That way if a state is updated, you are guaranteed that anything that is referencing it will also get updated.
|
|
|
|
|
How about you add a "Parent" property of type "State" that refers to the state the County is in? That way, States can have collections of Counties, and you are only modifying one collection still.
As far as binding to those Counties, perhaps you could create a wrapper class. It would internally store a collection of states and would expose each County in all those States. You could then bind to that wrapper class instance. You may want to do some work to make it observable as well.
Or instead of that wrapper, you could nest list views.
|
|
|
|
|
There are really two things you need to do here...
1) Build a list of Counties
2) Be able to, from a County, reference the "parent" State
Fortunately, both of these are easy to do:
For #1, a little LINQ makes this a snap.
Counties = States.SelectMany(state => state.Counties);
As for #2, you'll have to make some minor changes to your County object. I would suggest adding the State as a parameter in the constructor:
public County(State parent)
{
this.State = parent;
}
public State State { get; private set; }
That way, you can just bind to State.StateName.
|
|
|
|
|
i tried to print using the SL Printing API.
I'm wondering when does the Size of the PrintableArea change(usually it's 1122x793)??? and depending on what it change ???
thanks
"For as long as men massacre animals, they will kill each other. Indeed, he who sows the seed of murder and pain cannot reap joy and love." Pythagoras
modified on Wednesday, May 4, 2011 10:22 AM
|
|
|
|
|
The PageVisual refers to the UIElement that is being rendered out, so if you set it to point to the root element it refers to the size of the root element as measured for the print page. Following this, you can deduce that the size changes size based on the element it's printing out (for instance, if you set the PageVisual to an element that only fills half the width of the root element).
|
|
|
|
|
Thanks for the answer Pete and sorry for mistake as my query was regarding PrintableArea(not PageVisual).
"For as long as men massacre animals, they will kill each other. Indeed, he who sows the seed of murder and pain cannot reap joy and love." Pythagoras
|
|
|
|
|
Hi,
I have completed a WPF application in c#.
Now, I would like to start using the MVVM design pattern in this application.
At present, One of the windows forms i.e. frmPayment is populated as follows:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
DataTable _dtPayments = GetPayments(_intID);
DataView defaultView = _dtPayments.DefaultView;
dgPayments.ItemsSource = defaultView;
}
////////////////////////////////////////////////////////
Now, to get started with the MVVM, I have created a class called clsPaymentViewModel
with the following code:
public class clsPaymentViewModel : INotifyPropertyChanged
{
clsPaymentManager _PaymentManager = new clsPaymentManager();
public clsPaymentViewModel(int intID)
{
DataCollection = _PaymentManager.GetPayments(intID);
}
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
private ObservableCollection<clsPayment> mDataCollection;
public ObservableCollection<clsPayment> DataCollection
{
get { return mDataCollection; }
set
{
mDataCollection = value;
RaisePropertyChanged("DataCollection");
}
}
}
{
public ObservableCollection<clsPayment> GetPayments(int intID)
{
ObservableCollection<clsPayment> ret;
List<clsPayment> payments = GetPaymentsCol(intID);
ret = new ObservableCollection<clsPayment>(payments);
return ret;
}
}
public class clsPaymentManager
frmPayment has this code in it:
clsPaymentViewModel _ViewModel;
public frmPayment()
{
InitializeComponent();
int _intID = 1
_ViewModel = new clsPaymentViewModel(_intID);
}
//////////////////////
QUESTION:
Based on the above code, what should the DataContext be for dgPayment in frmPayment?
I was thinking of putting something like:
DataContext="{Binding Source={StaticResource clsPaymentViewModel}}"
But this is not right because there should be a _intID
What do you think please?
Thanks
|
|
|
|
|
At the top of the window definition define it like so:
<Window x:Class="MyWindow"
...etc...
xmlns:vm="clr-namespace:Namespace.VM.Is.In"
>
<Window.DataContext>
<vm:ViewModelClassName x:Name="viewModel" />
</Window.DataContext>
...etc...
</Window>
|
|
|
|
|
This is what I have in brief:
But not sure if _intID needs to be specified anywhere.
What do you think please?
<Window x:Class="frmPayment"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DataAccess;assembly=DataAccess"
Title="Payment" Height="336" Width="741"
...
<Window.Resources>
<!--<local:clsPaymentViewModel x:Key="clsPaymentViewModel" />
<Grid Width="804" Height="370">
<!--DataContext="{Binding Source={StaticResource clsPaymentViewModel}}"-->
<DataGrid AutoGenerateColumns="False" Height="124" Margin="5,169,86,0" Name="dgPayments" ;
<!--ItemsSource="{Binding Path=DataCollection}">-->
|
|
|
|
|
Hi,
I have a scenario wherein i need to migrate an existing Windows application of mine to an web application using silverlight. I am unable to add references of my existing C#2.0 dll's to the Silverlight projects due to CLR incompatibility.
Is there any way by which i can reuse my existing Entities,BusinessAccess layer and DataAccess Layer and only change the UI part?
|
|
|
|
|
Silverlight does not use the same version of the CLR as standard .NET applications. This means that you cannot use existing DLLs directly.
Let me explain in a bit more detail. When you run a .NET application (any .NET application), the CLR has a system called Fusion which works with the embedded assembly manifest (inside the DLL/exe). The manifest contains a load of information, such as embedded resources, type system details, and details of the required assemblies for this process (hint: this info is really useful for Reflection). Fusion won't find the desktop CLR references because the .NET BCL libraries aren't there as far as it's concerned (remember that it is aimed at targetting machines which may not have the full runtime installed).
If you want to add your existing code, the common trick is to create a bunch of new Silverlight class libraries and then add the class files into these libraries using the "Add as link" option in the add existing item (you add as a link so that if fix your existing application, your Silverlight application will get the fix simply by recompiling it). There are a couple of caveats though - as the class libraries are different, certain features may not be present so you may have to find workrounds (e.g. you can't add a reference to log4net). Silverlight also runs at a more secured level, so you can't do things like P/Invoke in the browser.
|
|
|
|
|
hi
Silvelright printing APIs aren't enough to custom printing.
Crystal Report is not supported in Silverlight (there isn't an Official version for Silverlight).
There is any other good solution for printing in silverlight ??? How did you print in your Silverlight Application ???
Thanks
"For as long as men massacre animals, they will kill each other. Indeed, he who sows the seed of murder and pain cannot reap joy and love." Pythagoras
|
|
|
|