In WPF Stretch a control to fill a ListView Column

After narrowing down my question I was about to Google and find an answer here. Basically for some reason the ListViewItems are set to align to the Left. Setting them to Stretch fixes this problem. This is done through a style like so: <ListView.ItemContainerStyle> <Style TargetType=”ListViewItem”> <Setter Property=”HorizontalContentAlignment” Value=”Stretch” /> </Style> </ListView.ItemContainerStyle> This unfortunately affects … Read more

How to check if a key/value pair exists in a Dictionary?

Well the pair can’t exist if the key doesn’t exist… so fetch the value associated with the key, and check whether that’s the value you were looking for. So for example: // Could be generic of course, but let’s keep things simple… public bool ContainsKeyValue(Dictionary<string, int> dictionary, string expectedKey, int expectedValue) { int actualValue; if … Read more

How Can I inherit the string class?

Another option could be to use an implicit operator. Example: class Foo { readonly string _value; public Foo(string value) { this._value = value; } public static implicit operator string(Foo d) { return d._value; } public static implicit operator Foo(string d) { return new Foo(d); } } The Foo class acts like a string. class Example … Read more

How to get instance of Panel that holds content of ItemsControl?

It’s a little tricky since you don’t know the name of the Panel so you can’t use FindName etc. This will work for most cases where an ItemsPresenter is present private Panel GetItemsPanel(DependencyObject itemsControl) { ItemsPresenter itemsPresenter = GetVisualChild<ItemsPresenter>(itemsControl); Panel itemsPanel = VisualTreeHelper.GetChild(itemsPresenter, 0) as Panel; return itemsPanel; } An implementation of GetVisualChild private static … Read more

How do I make a PictureBox use Nearest Neighbor resampling?

I needed this functionality also. I made a class that inherits PictureBox, overrides OnPaint and adds a property to allow the interpolation mode to be set: using System.Drawing.Drawing2D; using System.Windows.Forms; /// <summary> /// Inherits from PictureBox; adds Interpolation Mode Setting /// </summary> public class PictureBoxWithInterpolationMode : PictureBox { public InterpolationMode InterpolationMode { get; set; } … Read more

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