0

I have created application in WPF with two window. In one window i have used with one text box and submit button. Once submit from first window i hide first window and show second window. I have taken some values using first window text value and need to bind in second window Xaml. Actually that values can bind using foreach in html(mvc) but need to bind Xaml for display in second window. Please give some suggestions.

5
  • ItemsControl is the standard way to bind to a list of objects. Set ItemsSource to your list of objects, and create a DataTemplate to control the visual elements for each item. Commented Apr 4, 2017 at 14:40
  • No problem in that, data from first window should already be in some view-model. Use that viewmodel in another window. That's it. Commented Apr 4, 2017 at 14:41
  • Nice .. Thanks @BradleyUffner .. Commented Apr 4, 2017 at 15:30
  • Thanks @Divisadero for your suggestion Commented Apr 4, 2017 at 15:32
  • @ArunD No problem, if you need more info on how to do it, let me know Commented Apr 5, 2017 at 8:21

1 Answer 1

0

Please find the below answer, It will work definitely

Xaml :

<ItemsControl Name="icTodoList">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Grid Margin="200,50,0,30">
                                    <TextBlock>
                                       <Hyperlink TextDecorations="None" NavigateUri="{Binding UriPath}" RequestNavigate="Hyperlink_RequestNavigate"
                                                  CommandParameter="{Binding ElementName=myImg}">
                                                        <Image HorizontalAlignment="Left" Width="80" Height="80"  x:Name="myImg" Source="{Binding Source}" Margin="5"/>
                                       </Hyperlink>
                                    </TextBlock>

                                    <TextBlock TextAlignment="Left" Margin="200,30,0,0">
                                            <TextBlock FontSize="22px" Text="{Binding Title}" Foreground="white"></TextBlock>
                                    </TextBlock>
                                </Grid>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>

C# code for binding Values,

 public class DMScreen3 {
    public List<string> AllFiles { get; set; }
              List<BindingFilesContent> items = new List<BindingFilesContent>();
                    if(AllFiles != null)
                    {
                        foreach(var r in AllFiles)
                        {
                            if ((r.ToLower().Contains(".avi") || r.ToLower().Contains(".mp4")) && fileTypes == "video")
                            {
                                items.Add(new BindingFilesContent() { Title = Path.GetFileName(r), UriPath = r, Source = "/images/videoicon.png" });
                            }
        icTodoList.ItemsSource = items;
                  }
        }
}
  public class BindingFilesContent
    {
        public string Title { get; set; }
        public string Source { get; set; }
        public string UriPath { get; set; }
    }
Sign up to request clarification or add additional context in comments.

Comments

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.