|
something like 101 wpf sample projects.
I searched google but there is nothing similar.
thanks
|
|
|
|
|
|
|
Hello,
I have two listboxes arranged side by side in a Grid control.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="40" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<ListBox Grid.Column="0" Name="supply" HorizontalAlignment="Stretch" />
<!-- buttons -->
<ListBox Grid.Column="2" Name="select" HorizontalAlignment="Stretch" />
</Grid>
I want both listboxes to have the same width, regardless of the (text) content of the listboxes.
Initially, the left listbox contains a list of strings. The right listbox is empty. If the maximum width of the items in the left listbox is smaller than (roughly) half of the size allocated to the entire grid, everything is ok. Otherwise, the left listbox occupies whatever width is needed to display the widest visible item, and the other list gets the rest.
I suppose that the grid "asks" each listbox what width it wants, and they in turn ask their items. I'd like to stop the process before the width of the items gets involved, IOW both listboxes should report minimal width, then the grid would have plenty of space on its hands, which it would split evenly between the two listboxes.
How can I achieve that ?
I've seen suggestions on the web, involving either SharedSizeGroup or disabling the listbox' horizontal scrollbar and setting HorizontalContentAlignment to "Stretch". They don't seem to work...I also tried binding the left listbox' MaximalWidth the the right listbox' Width, to no avail.
|
|
|
|
|
The code you posted should do exactly what you want.
When you use star-sizing, the grid does NOT resize columns based on child control sizes... First it sets the size of fixed columns (Like your "40"), then it figures out the size of "Auto" columns by asking the controls in those columns what they need, then it splits up the remainder into the star-sized columns.
My suggestions would be:
1) Make sure the grid itself isn't the piece resizing... If it's inside, say, a ScrollViewer, then it'll enlarge itself to (2 x the widest listbox) + 40... It might be the grid itself being cut off on the right, not the second listbox
2) If your actual code is more complex than this (And I suspect it is), try commenting out a piece at a time until you see the behavior you're expecting.
|
|
|
|
|
Ian Shlasko wrote: When you use star-sizing, the grid does NOT resize columns based on child control sizes... First it sets the size of fixed columns (Like your "40"), then it figures out the size of "Auto" columns by asking the controls in those columns what they need, then it splits up the remainder into the star-sized columns.
That's the way I understand it. But I suspect that the listbox in turn examines the items to answer "what it needs".
When I limit the number of characters in the text items for a test, everything works perfectly. So the content of the listbox does matter. I think.
|
|
|
|
|
Except, in the code you posted, the listbox is in a star-sized column, not an Auto column. A star-sized one will always take up a fraction of the remaining width after fixed and auto columns, calculated by dividing its star width by the total star width (1* / (1* + 1*) = 1/2).
Yes, the listbox would resize itself based on its contents, but the grid tells it what rectangle it's supposed to fill, and in this case, that rectangle will have nothing to do with the ListBox contents.
So like I said... Check that the grid itself isn't enlarging, and then try reducing your code until the problem is eliminated (to track down the exact cause).
|
|
|
|
|
Indeed the Grid containing the Listboxes was inside a StackPanel inside a ScrollViewer with HorizontalScrollBarVisibility="Auto". Which caused the problem.
Thanks for helping,
J-L
|
|
|
|
|
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.
|
|
|
|
|