Button in a column, getting the row from which it came on the Click event handler

Basically your button will inherit the datacontext of a row data object. I am calling it as MyObject and hope MyObject.ID is what you wanted. private void Button_Click(object sender, RoutedEventArgs e) { MyObject obj = ((FrameworkElement)sender).DataContext as MyObject; //Do whatever you wanted to do with MyObject.ID }

HorizontalAlignment=Stretch, MaxWidth, and Left aligned at the same time?

You can set HorizontalAlignment to Left, set your MaxWidth and then bind Width to the ActualWidth of the parent element: <Page xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”> <StackPanel Name=”Container”> <TextBox Background=”Azure” Width=”{Binding ElementName=Container,Path=ActualWidth}” Text=”Hello” HorizontalAlignment=”Left” MaxWidth=”200″ /> </StackPanel> </Page>

How to format number of decimal places in wpf using style/template?

You should use the StringFormat on the Binding. You can use either standard string formats, or custom string formats: <TextBox Text=”{Binding Value, StringFormat=N2}” /> <TextBox Text=”{Binding Value, StringFormat={}{0:#,#.00}}” /> Note that the StringFormat only works when the target property is of type string. If you are trying to set something like a Content property (typeof(object)), … Read more

How to get the size of the current screen in WPF?

I created a little wrapper around the Screen from System.Windows.Forms, currently everything works… Not sure about the “device independent pixels”, though. public class WpfScreen { public static IEnumerable<WpfScreen> AllScreens() { foreach (Screen screen in System.Windows.Forms.Screen.AllScreens) { yield return new WpfScreen(screen); } } public static WpfScreen GetScreenFrom(Window window) { WindowInteropHelper windowInteropHelper = new WindowInteropHelper(window); Screen screen … Read more

How to format TimeSpan in XAML

The format string is intended to work on a DateTime, not a TimeSpan. You could change your code to work with DateTime.Now instead. Your xaml is fine: <TextBlock Text=”{Binding MyTime,StringFormat=HH:mm}”/> Update And from .Net 4 format a TimeSpan as follows: <TextBlock Text=”{Binding MyTime,StringFormat=hh\\:mm}”/>

WPF Binding StringFormat Short Date String

Try this: <TextBlock Text=”{Binding PropertyPath, StringFormat=d}” /> which is culture sensitive and requires .NET 3.5 SP1 or above. NOTE: This is case sensitive. “d” is the short date format specifier while “D” is the long date format specifier. There’s a full list of string format on the MSDN page on Standard Date and Time Format … Read more

What does mc:Ignorable=”d” mean in WPF?

The mc:Ignorable namespace provides xaml definitions that are “ignored” by the xaml processor. This allows you to specify information used by the designer at design time which is ignored at runtime. In your case, you can specify DesignHeight and DesignWidth, which are not “real” properties on a Window, but work in the designer for providing … Read more

How to set a binding in Code?

Replace: myBinding.Source = ViewModel.SomeString; with: myBinding.Source = ViewModel; Example: Binding myBinding = new Binding(); myBinding.Source = ViewModel; myBinding.Path = new PropertyPath(“SomeString”); myBinding.Mode = BindingMode.TwoWay; myBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; BindingOperations.SetBinding(txtText, TextBox.TextProperty, myBinding); Your source should be just ViewModel, the .SomeString part is evaluated from the Path (the Path can be set by the constructor or by the … Read more

WPF Auto height in code

Perhaps this link will help you. At times, you may want to programmatically set the Height or Width of a WPF element to Auto in code. To do this, just use the Double.NaN (Not a Number) value. For example, in C#: this.txtName.Width = Double.NaN;

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)