|
You cant do that in XAML, because you need to check which listbox width is higher.
You can add event handler on event which occurs when you already know widths of both listboxes.
For examole: Loaded, Binding.SourceUpdated or smth like this.
Also, if you want to avoid streching of listbox, you have to set colums width="auto":
<ColumnDefinition Width="auto" />
|
|
|
|
|
I created a SL4 application that loads DB from an SQL2K8 server. I want to do it in code.
The grid is initiated as follows:
public MainPage()
{
InitializeComponent();
MTXDomainContext context = new MTXDomainContext();
dataGrid1.ItemsSource = context.compntNames;
context.Load(context.GetCompntNamesQuery());
.
.
.
So my question is:
How can I load just desired columns?
Can I modified the generated code (sample below)to select certain columns?
public IQueryable<compntName> GetCompntNames()
{
return this.ObjectContext.compntNames;
}
Any help is greatly appreciated
|
|
|
|
|
HI,
In my application, i have to do something like that, checking the duplicate of data or checking wether the directive name in my listbox data template is empty or not,
Because when the user click on the button to insert new directive it has to check the listbox like wether the directive name is null or not, so can u tell me how to do it..
I have used a code like this,
public void LoadDirective()
{
listdata = new ObservableCollection<DADirective>();
SelectDirective = (DADirective)lbDirectiveList.SelectedItem;
listdata.Add(new DADirective { DirectiveName = "Filter trading account", DirectiveDescription = "Rows will Trading account value to be filtered" });
listdata.Add(new DADirective { DirectiveName = "Filter Counter party rows", DirectiveDescription = "Rows where counter party is null will be filtered" });
listdata.Add(new DADirective { DirectiveName = "Filter USD currency records", DirectiveDescription = "Filter those rows where currency is USD" });
lbDirectiveList.ItemsSource = listdata;
}
private void btnNewDirectiveClicked(object sender, RoutedEventArgs e)
{
gDirectiveDetails.IsEnabled = true;
gDerivedCondition.IsEnabled = true;
DADirective dirdata = new DADirective { };
if (!listdata.Contains(dirdata))
{
if (listdata.Count >= 0)
{
listdata.Add(new DADirective { });
lbDirectiveList.SelectedIndex = listdata.Count - 1;
txtDirectiveName.Focus();
}
}
}
This is my xaml code..
<ListBox Grid.Row="1" Grid.Column="2" x:Name="lbDirectiveList" ItemsSource="{Binding}" SelectionChanged="lbDirectiveList_SelectionChanged" MaxHeight="200" SelectionMode="Single" ScrollViewer.VerticalScrollBarVisibility="Auto">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="25" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Name="tbDirName" Text="{Binding Path=DirectiveName, Mode=TwoWay}" Grid.Column="0" FontWeight="Bold" MinWidth="200"/>
<TextBlock Text=" - " Grid.Column="1"/>
<TextBlock Grid.Column="2" Name="tbDirDesc" Text="{Binding Path=DirectiveDescription, Mode=TwoWay}" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
so how can to read the data in this listbox, i have used a foreach loop like foreach(var dir in listdata), but it is giving exception in case of directive insert, so is there any other way for this...
|
|
|
|
|
Hei you dont need to read the data in the listbox instead you can access the source binded in the ListBox.
lbDirectiveList.ItemsSource
India is Mythical and so we are
|
|
|
|
|
As I told you before[^], you only need to use the ObservableCollection to read the data.
|
|
|
|
|
I need to be able to model and manipulate a 3d graphic base on iges, step or catpart format.
Can somebody show me some example or open source or commercial sdk that allows me to do that.. I need to integrate it in my app.
I really appreciate your help guys..
Rafael
Rafael Tejera
|
|
|
|
|
I have a NumericTextBox control which inherits from TextBox.
It capture key input to only accept valid character, it also have various property such as Min, Max, Precision, etc...
When the Text property is updatde it turns it into a decimal, validate the value and set the "Value" property.
Now, when I consume this item I bind to the "Value" property.
Here lies the problem.
When I update the Value property at InitializeComponent() time (when setting the Precision for example) the Binding on Value is destroyed!
How could I work around this problem?!
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.
|
|
|
|
|
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).
|
|
|
|