0

I am writing a Sudoku application in c# and WPF. I got the grids with my Textboxes so far, but now i want to fill it with a Array of Arrays ([][]).

For my first tests i found a way to do this manually. XAML:

 <TextBox> Text="{Binding Path=Testarr[0][0]}" Name="testbox"></TextBox>

and in my xaml.cs:

testbox.DataContext = this;

So now my Textbox show the value which is initialized in Testarr[0][0].

For my Sudoku i have 81 textboxes, and i don´t want to initialize all of them manually, is there a way to do it simple?

1
  • Yes. MVVM. ItemsControl with ItemTemplate. But that would require learning something, so just write a perl script to generate all the XAML with bindings. Commented Nov 23, 2016 at 15:13

1 Answer 1

1

You can have a look here where it shows how to use an ItemsControl to create your grid.

    <ItemsControl ItemsSource="{Binding MyCollection}">
        <!-- ItemsPanelTemplate -->
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <UniformGrid Columns="2" />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
 
        <!-- ItemTemplate -->
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Button Content="{Binding }" />
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
Sign up to request clarification or add additional context in comments.

1 Comment

Using a TwoWay binding, the user input will automatically be set to the matching view-model instance.

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.