|
The ScrollContentPresenter comes from the default template of ListBox (or more accurately, the ScrollViewer that a ListBox creates). The ScrollContentPresenter is the region inside a ScrollViewer that is not used by the scroll bars. When I first replied, I was rather hasty with the copy and paste of the WrapPanel. You really do not need several of those properties set.
<WrapPanel
Name="wrapPanel"
MinHeight="17"
Width="{Binding ActualWidth,
RelativeSource=
{RelativeSource AncestorType={x:Type ScrollContentPresenter}}}"
IsItemsHost="True"
Orientation="Horizontal"
HorizontalAlignment="Left"
/>
The Name is not useful because you won't be able to access the panel by name anyway. The IsItemsHost is ignored because it is already in the ItemsPanelTemplate. The default HorizontalAlignment is always what you end up wanting.
There are several possible reasons that come to mind for why the control is not sizing back down. One is that the when you are using the UserControl elsewhere, the sizing is not bound correctly and is thus only growing. Another option is that some other control in the the grid where you use this control is not sizing back down. If you are doing manual sizing in the code-behind somewhere else in the application where this control is used, that could be preventing the control from sizing back down. (In general, you should not have explicit sizes, except on windows, or mess with sizes in the code-behind in WPF. The automatic sizing should be able to handle most cases.) Some XAML from where this control is used may show the problem.
As a aside for design philosophy, does this UserControl do something special other than select horizontal wrap panel by default? If not, you would probably be better off defining a Style and applying it to any ListBox that you want to have this look and items panel. If you do leave this as a UserControl, you should take out the explicit ScrollViewer since the ListBox will create a ScrollViewer internally if needed.
|
|
|
|
|
The most important thing you wrote in your post is the following:
Gideon Engelberth wrote: If you do leave this as a UserControl, you should take out the explicit ScrollViewer since the ListBox will create a ScrollViewer internally if needed.
Removing ScrollViewer solved all my problems! It now wraps properly on the fly whether I make the dialog wider or narrower. Thank you very much for pointing this out. I thought only TextBox and RichTextBox had built-in scrollbars.
But let me comment on your other suggestion that I define a style instead of creating a UserControl. I did not embark on this decision lightly! The code behind in the UserControl is about 600 lines of C#. There is all kinds of data analysis required to style the individual ListBoxItems: different colors, different font styles, different font weights, underlining, all determined by the semantics of what the user types in. The original content of each ListBoxItem starts out as a TextBox that the user can type into. When he presses the Enter key, the code behind changes the ListBoxItem.Content to either a heavily styled TextBlock or a horizontal StackPanel with graphics and a styled TextBlock. The graphics in the StackPanel indicates to the user what will happen when he double-clicks the containing ListBoxItem. There are also several custom dependency properties and routed events that are defined in the UserControl. I don't think all this could be done just with styles.
I removed the Name (residual when I was trying various incarnations of FindName that did not work), IsItemsHost, and HorizontalAlignment.
|
|
|
|
|
That's a pretty decent reason to have a custom control. The only other approach I would suggest as a possibility is to wrap the coloring, styling, TextBox to StackPanel stuff into a UserControl of its and use that control as the ItemTemplate for a normal ListBox. Depending on how much of that 600 lines is needed to determine which TextBox is being entered in and which item to update, there could be some big savings by wrapping that into its own control.
|
|
|
|
|
I'm trying to debug one of my Silverlight 3 applications.
I go into debug mode and launch the page, but my breakpoints say they will never be hit because no symbols have been loaded. This just started! Has anyone seen this and how do I fix it???
My project is in debug mode, debugging is turned on, it is attached to the local test environment. Everything checks out except for the fact that I cannot stop my code and it appears nothing is executing correctly. (expected web service not getting called which I am able to properly place in debug mode)
Help!
|
|
|
|
|
I've always just needed to kill the app, flush
the browser cache to force reloading a new XAP,
and run it again.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark,
I flushed my cache (I think...you know how they changed everything around in Windows 7) I searched and deleted all of my xap files, and I still get the 'symbols not loaded' message after loading the page object!!
Any other suggestions?
Thanks,
Michael
|
|
|
|
|
Go to the properties of your web project, select web on the left and then scroll down to the end of the page.
Make sure that the ASP.Net and Silverlight Debuggers are checked.
|
|
|
|
|
It seems that when I refreshed my project from SVN, it did not save the debug settings. It reset my debug switches, which I was not expecting.
Thanks to you and Mark....I'm back in debug state!!!
|
|
|
|
|
Michael Eber wrote: I'm back in debug state
Great.
Me, I'm dishonest. And a dishonest man you can always trust to be dishonest. Honestly. It's the honest ones you want to watch out for...
|
|
|
|
|
|
can anybody tell me is isolated storage in silverlight is permanent ?
because once i restart my system all the files which i created in my isolated storage are deleted
and also if i close my visual studio and reopen it than it also removes all the
previously created files .
any help ?
regards.
Tauseef A Khan
MCP Dotnet framework 2.0.
|
|
|
|
|
Tauseef A wrote: is isolated storage in silverlight is permanent ?
Permanent until a user or an application deletes something.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Tauseef A wrote: because once i restart my system all the files which i created in my isolated storage are deleted
and also if i close my visual studio and reopen it than it also removes all the
previously created files
There are two types of isolated storage - "Application" and "Site". Both are scoped by the user..since the files are stored under the user's AppData on Windows. These are permanent and not cleared even when you clear the browser's cache or restarting the system.
Now...bring me that horizon. And really bad eggs...Drink up me hearties, YO HO!
|
|
|
|
|
|
Make sure you call the update method or the changes aren't committed
|
|
|
|
|
Hi,
Do you know any ListView styles sample in XAML code ?
Thanks.
|
|
|
|
|
|
Here is my setup:
I have a ListBox which contains an ItemTemplate.
The ItemTemplate incorporates a checkbox with name/checked state bound to the ItemSource object.
issue: when the checkbox is checked (or unchecked) the selected event is not picked up. Basically you have to click the checkbox text on the far right to actually select it.
This can be a rather delecate issue as a user may think they are setting values for the item they checked but actually changing values for a previously selected item.
Is there something in the xaml I can set or do I handle the checked event and set that object to selected item?
|
|
|
|
|
If I'm reading correctly - the checkbox button
is eating the mouse click events (like buttons do)
so the listbox selection doesn't change, correct?
If so, I would try adding Checked/Unchecked event
handlers to the CheckBox. In the handlers, the sender
parameter will be the CheckBox. The CheckBox's DataContext
should be a reference to the selected item in the ListBox's
ItemsSource. Set the listBox's SelectedItem property to
the CheckBox's DataContext value.
(Note I didn't test this )
private void CheckBox_Checked(object sender, RoutedEventArgs e)
{
myListBox.SelectedItem = (sender as CheckBox).DataContext;
}
private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
{
myListBox.SelectedItem = (sender as CheckBox).DataContext;
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark,
Yup, you understood correctly, the checkbox is gobbling up the event and the listbox does not select the item. I pretty much thought I'd have to do what you suggested, setting listbox.SelectedItem to the corresponding checkbox.
Thanks Mark,
Michael
|
|
|
|
|
I added a code sample to my post....does it work?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
yuppers, that worked.
|
|
|
|
|
Good to know, thanks!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
Hi,
I have created a 3D object in WPF using c#. I would like to make them transparent. I tried reducing the alpha value in color palette. Also, I tried to use Opacity property of Brush(Eg: brush.Opacity = 0.25;). Both of them doesn't seem to work. Could some one give some suggestions. Thanks in advance!!!
|
|
|
|
|
Well the alpha should take care of this for you. You can look at my article on XAML Series 2. It should some alpha blending. Mostly depends on what is being over laid over what. The example is a silverlight applet that uses what I call a sparkel filter, the filter uses different alpha values to create a star burst pattern in a matrix to give the desired effect.
If you want the whole window to be transparent you need to set the aplha values all the way down the widget hierarchy.
|
|
|
|
|
Hi,
I am making a mini paint like application using WPF.. Does anyone know how to go about implementing a Pencil tool in WPF (C# preferred.)
thanks in advance.
|
|
|
|