Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
H

Henrik Jonsson

@Henrik Jonsson
About
Posts
7
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Generate a WPF-Menu based on a XML-document
    H Henrik Jonsson

    You should start to read about XmlDataProvider and how to use bindings to XML-documents with XPath. A good starting point can be How to: Bind to XML Data Using an XMLDataProvider and XPath Queries | Microsoft Docs[^] In the example a ListBox is populated but you should be able to replace it with a Menu bound to an XmlDataProvider as ItemsSource with a customized ItemContainerStyle that sets the Header of the MenuItem to the title attribute. Good luck.

    C# csharp wpf xml help

  • Reference Material for creating/documenting Software architecture
    H Henrik Jonsson

    As already pointed out learning UML is a good starting Point for a object-oriented language like Java. I can recommend the book "Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development" by Craig Larman [^] to learn about how to actually apply modelling in real scenarios.

    Design and Architecture java design architecture

  • ListBox Style Problem
    H Henrik Jonsson

    Hello, the problem is that the default control template for ListBoxItem contains a border element which controls the background color. To fully control the appearance you could replace the template using the template from ListBoxItem ControlTemplate Example[^] with your own definition. See below for an example.

    <Style x:Key="listBoxItemContainerStyle" TargetType="{x:Type ListBoxItem}">
    <Setter Property="SnapsToDevicePixels" Value="true"/>
    <Setter Property="OverridesDefaultStyle" Value="true"/>
    <Setter Property="Foreground" Value="Black"/>
    <Setter Property="Template">
    <Setter.Value>
    <ControlTemplate TargetType="ListBoxItem">
    <Border Name="Border" Padding="2" SnapsToDevicePixels="true">
    <ContentPresenter />
    </Border>
    <ControlTemplate.Triggers>
    <Trigger Property="IsSelected" Value="true">
    <Setter TargetName="Border" Property="Background" Value="Orange"/>
    <Setter Property="Foreground" Value="Blue"/>
    </Trigger>
    <Trigger Property="IsEnabled" Value="false">
    <Setter Property="Foreground" Value="Gray"/>
    <Setter TargetName="Border" Property="BorderThickness" Value="2"/>
    </Trigger>
    <Trigger Property="IsMouseOver" Value="true">
    <Setter TargetName="Border" Property="Background" Value="Orange"/>
    <Setter Property="Foreground" Value="Blue"/>
    </Trigger>
    </ControlTemplate.Triggers>
    </ControlTemplate>
    </Setter.Value>
    </Setter>
    </Style>

    WPF help database question

  • code dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString() doesnt work
    H Henrik Jonsson

    Hi, when you get "Object reference not set to an instance of an object" exceptions some of the properties you invoke have returned null, in this case most likely Value for an empty grid cell. Check the Value for null before using it:

    var gridValue = dataGridView1[e.ColumnIndex, e.RowIndex].Value;
    if( gridValue != null )
    {
    string gridStringValue = gridValue.ToString();
    ...
    }

    C# help

  • The Web can make you lose your religion, study says
    H Henrik Jonsson

    The Internet certainly helps us to widen our view of the world, so the religions may have to adapt, but to what point? During the service yesterday the priest started her preachment by refeering to Goooooogle when explaining "reconciliation". Is the search enginge our new god, having all the answers and knowing more about us than ourselves? Maybe we have to reconcile us with that fact too?

    The Insider News com announcement

  • Shortest Way to Shuffle Array
    H Henrik Jonsson

    Hi again, using the Fisher-Yates shuffling algorithm [^] seems to be superior in performance:

    public static void Shuffle(T[] array)
    {
    Random rnd = new Random();
    for (int i = array.Length - 1; i >= 0; i--)
    {
    int index = rnd.Next(i);
    T temp = array[index];
    array[index] = array[i];
    array[i] = temp;
    }
    }

    C# data-structures

  • Shortest Way to Shuffle Array
    H Henrik Jonsson

    This generic function provides a quick way of randomly shuffling (reordering) the items in-place in an existing array:

    public static void ShuffleArray(T[] array)
    {
    Random rnd = new Random();
    int[] order = new int[array.Length];
    for (int i = 0; i < array.Length; i++)
    {
    order[i] = rnd.Next();
    }
    Array.Sort(order, array);
    }

    It can we rewritten as

    Random rnd = new Random();
    Array.Sort(array.Select(r => rnd.Next()).ToArray(), array);

    giving just slightly worse performance. According to my tests the use of Array.Sort is about three times faster than the OrderBy solution for a million integer array.

    C# data-structures
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups