0

I have a short question about WPF and C#. Can somebody give me an example how the following xaml code would look in C# code?

In xaml this works, but i would like to do some dynamic C# creation and need to do this in C# code as well. I am able to do every bit of binding in code, except this part..

<GridViewColumn>
    <GridViewColumn.CellTemplate>
         <DataTemplate>
              <Image Source="{Binding FileImage, Converter={StaticResource imageConverter}}" Width="32" Height="32"/>
         </DataTemplate>
    </GridViewColumn.CellTemplate>
</GridViewColumn>

The way i load my other columns is like this:

leftColumnOne = new GridViewColumn();
leftColumnOne.Header = "First name";
leftColumnOne.DisplayMemberBinding = new Binding("FirstName");
7
  • Try it social.msdn.microsoft.com/Forums/vstudio/en-US/… Commented Dec 4, 2013 at 14:19
  • Check this out. Commented Dec 4, 2013 at 14:47
  • Don't create or manipulate UI elements in procedural code in WPF. That's what XAML is for. - There's no need to "dynamically define the columns in a ListView" - How many different combinations of columns do you really have? - You should be using DataTemplates to provide different Views for different data sets, not using a horrible winforms-like procedural approach. Commented Dec 4, 2013 at 14:58
  • Unfortunately i have an exception on this part, this must be dynamic. the xaml is to static for this case, because i'm using a WPF window with a page inside it that needs to update the gui dynamically. And the two examples work fine with TextBlocks, but my Image needs to be converted. Therefore i need to know how to use this code including a IValueConverter. Commented Dec 4, 2013 at 15:17
  • @stackr No XAML is not static. You have no idea what you're talking about. Please learn WPF properly and don't try to use it as if it were winforms. There are many ways to achieve a dynamic column behavior in a ListView, however my question if you really need this remains unanswered. How many different combinations of columns will there be? Commented Dec 4, 2013 at 15:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.