|
There - I balanced that out a bit.
"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
|
|
|
|
|
mehdibahadori wrote: equivalent method Dispose()(in c#) in WPF?
Huh!!! WPF is a subset of .Net Framework & it is mainly for the UI. Hence you are using C# as the backend code. So why you are asking about an equivalent method of Dispose() (in C#)??? For your information... there are no alternatives. You have to use the same... which you have to implement from IDisposable interface.
Regards,
- Kunal Chowdhury ( My Blog)
|
|
|
|
|
|
|
Attached properties need different getters and setters than regular ones...
See the example near the end of this page: http://msdn.microsoft.com/en-us/library/ms749011.aspx[^]
EDIT: Oh, and make sure you really want an attached property here. You might want to use a regular dependency property, then bind it using a RelativeSource with FindAncestor.
|
|
|
|
|
|
Sure... Here's the quick and dirty on both...
Dependency Property = Just a property on a class that automatically updates data binding (At the cost of a little overhead)
Attached Dependency Property = A property that goes down the tree. Think of DockPanel.Dock. It's made so child controls can have a value, but the parent stores them and can act on them. It's most similar to the old ExtenderProviders from WinForms.
As for the binding... Data binding is actually one of the more annoying parts of WPF, but it's great once you get it right. I still have to use references pretty often for the more complicated binding sources...
Every control has what's called a DataContext. This is just any old object you assign to it. It's the source for any data binding. So if you say "{Binding IsValidNewSet}", the first place it will look is in the button's DataContext property. Since it doesn't have one, it'll crawl up the tree and check the Grid's DataContext (Also missing), then the Window's DataContext... It doesn't find one, so you'll have problems.
Now, you COULD set the window's datacontext to itself in the code-behind, so the button would eventually see the Window as its datacontext and get the IsValidNewSet property. It's not the best way though...
The simplest way is to bind by name. Give the window a name in XAML, for example "MyWindow". Then use this binding for the button:
IsEnabled="{Binding ElementName=MyWindow,Path=IsValidNewSet}"
Come to think of it, I was going to post the code for a FindAncestor call, but that might be overkill... I'd say just use ElementName. This overrides the normal behavior and looks at a named element instead of the DataContext.
|
|
|
|
|
|
Ahhh, ok, you're doing this as a UserControl. Then you DEFINITELY want to use FindAncestor instead of ElementName. WPF has some limitations when it comes to XAML-defined UserControls, and those get worse if you start naming their component elements.
You won't run into most of the annoyances unless you start templating, but it's still something to watch out for.
Oh, but the name you define inside the UserControl is an internal name, so instantiating it elsewhere would not override it in this sense.
|
|
|
|
|
|
Heh, well good luck
|
|
|
|
|
|
Ah, ok... I posted another solution above... Looked at your code again, and thought this might be a little much... You nailed it, though.
As for the types.... Well, Window1 is a Window, right? Basically this is saying "Walk up the tree until you find an object that's a Window, and use that as the binding source"
|
|
|
|
|
Rather than do this - use a notification property, as in:
public class NewSet : INotifyPropertyChanged
{
private bool _isValid;
public bool IsValidNewSet
{
get { return _isValid; }
set
{
if (_isValid != value)
{
_isValid = value;
OnChanged("IsValidNewSet");
}
}
}
protected virtual void OnChanged(string propertyName)
{
PropertyChangedEventHandler handler = propertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName);
}
}
public event PropertyChangedEventHandler PropertyChanged
{
add { propertyChanged += value; }
remove { propertyChanged -= value; }
}
private event PropertyChangedEventHandler propertyChanged;
} Then, set this up as your DataContext , e.g. in Window1 (probably just after you call InitializeComponent() ), set your DataContext to an instance of this class.
Finally, in your XAML, all you need do is bind to this item using:
<Button IsEnabled="{Binding IsValidNewSet}" />
"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
|
|
|
|
|
|
Has anyone tried to get silverlight 3 to work with Blend 2?
|
|
|
|
|
No - I've used Blend 3 instead (the RC) - if you've got MSDN, Blend 3 RTM is available to download now.
"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 do and when I checked it wasn't there, like 2 days ago. I see it's there now so thanks.
|
|
|
|
|
Pete O'Hanlon wrote: if you've got MSDN, Blend 3 RTM is available to download now
Thanks! That slipped under my radar
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
We need to host MS Office applications(integrate) in WPF. I tried web browser but that supports only PDF hosting.
Then there is DSO Framer control, but that uses Windows host as root element. There we loose some flexibilty(Like dynamic resizing of window etc.).
Is there a better way out
Thanks
|
|
|
|
|
amit_1986 wrote: I tried web browser but that supports only PDF hosting
No it doesn't. It's just a standard web browser - if you can open your document in IE, you can open it in the web browser component.
"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 a bunch of 3D models that gets rendered on startup. I can easily select any model using Hit Testing. My question is, how can I rotate the selected model using the directional keys on the keyboard?
|
|
|
|
|
Set a RotateTransform3D on your model and implement a command handler that works out which key was pressed and updates the transform as appropriate.
"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,
We have a web server which sends data to online application and client wpf application to render some controls.
The dimensions of controls is set by server in pixels. Controls are rendering fine in online application, but in client wpf application controls are rendering with very small dimensions. Is there any conversion factor to render wpf controls using pixels dimensions which work just fine for web application?
Any help will be useful.
Thanks
|
|
|
|
|