Hej, jeg sidder her og er ved at udvikle en app til windows phone. Og jeg gør det i c#.
Jeg hare lidt problemer med at få det til at virke.
Jeg har en function, som automatisk laver et grid og tilføjer det til en stackpanel. I denne grid er der en knap. Med den kunne jeg godt tænke mig at ændre visibillity på det grid den er i. Men kan pt ikke få det til at virke
mit XAML er:
- <ScrollViewer x:Name="nyheds_scroll" Margin="0,75,0,0">
- <StackPanel x:Name="news_stackpanel_xaml" VerticalAlignment="Stretch" Margin="0,0,0,0">
- </StackPanel>
- </ScrollViewer>
og mit c# kode er:
- public Grid create_grid_new(string overskrift, string content, string in_image_source, int create_grid_offset)
- {
- Grid tempgrid = new Grid();
- Image nyheds_billed = new Image();
- Button button_button = new Button();
- TextBlock overskrift_textblock = new TextBlock();
- TextBlock content_textblock = new TextBlock();
- MainPage m = new MainPage();
- // Create the Grid
- tempgrid.Width = 477;
- tempgrid.HorizontalAlignment = HorizontalAlignment.Stretch;
- tempgrid.VerticalAlignment = VerticalAlignment.Stretch;
- tempgrid.ShowGridLines = false;
- tempgrid.Visibility = Visibility.Visible;
- tempgrid.Background = new SolidColorBrush(Colors.White);
- // Create the image
- Uri image_source = new Uri(in_image_source, UriKind.Absolute);
- ImageSource imgSource = new BitmapImage(image_source);
- image_grid.Add(nyheds_billed);
- image_grid[image_grid.Count -1].Height = 108;
- image_grid[image_grid.Count - 1].Width = 196.524597167969;
- image_grid[image_grid.Count - 1].Source = imgSource;
- image_grid[image_grid.Count - 1].Visibility = Visibility.Visible;
- image_grid[image_grid.Count - 1].Margin = new Thickness(0, create_grid_offset + 10, 0, 0);
- image_grid[image_grid.Count - 1].VerticalAlignment = VerticalAlignment.Top;
- image_grid[image_grid.Count - 1].HorizontalAlignment = HorizontalAlignment.Left;
- Grid.SetRow(image_grid[image_grid.Count - 1], 1);
- Grid.SetColumn(image_grid[image_grid.Count - 1], 1);
- Grid.SetRowSpan(image_grid[image_grid.Count - 1], 1);
- Grid.SetColumnSpan(image_grid[image_grid.Count - 1], 1);
- // Create the header
- overskrift_grid.Add(overskrift_textblock);
- overskrift_grid[overskrift_grid.Count - 1].Text = overskrift;
- overskrift_grid[overskrift_grid.Count - 1].FontSize = 36;
- overskrift_grid[overskrift_grid.Count - 1].Height = 50;
- overskrift_grid[overskrift_grid.Count - 1].Width = 477;
- overskrift_grid[overskrift_grid.Count - 1].Visibility = Visibility.Visible;
- overskrift_grid[overskrift_grid.Count - 1].Foreground = new SolidColorBrush(Colors.Black);
- overskrift_grid[overskrift_grid.Count - 1].Margin = new Thickness(0, create_grid_offset + 118, 0, 0);
- overskrift_grid[overskrift_grid.Count - 1].VerticalAlignment = VerticalAlignment.Top;
- overskrift_grid[overskrift_grid.Count - 1].HorizontalAlignment = HorizontalAlignment.Left;
- overskrift_grid[overskrift_grid.Count - 1].TextWrapping = TextWrapping.Wrap;
- Grid.SetRow(overskrift_grid[overskrift_grid.Count - 1], 1);
- Grid.SetColumn(overskrift_grid[overskrift_grid.Count - 1], 1);
- Grid.SetRowSpan(overskrift_grid[overskrift_grid.Count - 1], 1);
- Grid.SetColumnSpan(overskrift_grid[overskrift_grid.Count - 1], 1);
- // Add second column header
- content_grid.Add(content_textblock);
- content_grid[content_grid.Count - 1].Text = content;
- content_grid[content_grid.Count - 1].FontSize = 20;
- content_grid[content_grid.Count - 1].Height = 78;
- content_grid[content_grid.Count - 1].Width = 477;
- content_grid[content_grid.Count - 1].Visibility = Visibility.Visible;
- content_grid[content_grid.Count - 1].Foreground = new SolidColorBrush(Colors.Black);
- content_grid[content_grid.Count - 1].VerticalAlignment = VerticalAlignment.Top;
- content_grid[content_grid.Count - 1].HorizontalAlignment = HorizontalAlignment.Left;
- content_grid[content_grid.Count - 1].Margin = new Thickness(0, create_grid_offset + 173, 0, 0);
- content_grid[content_grid.Count - 1].TextWrapping = TextWrapping.Wrap;
- Grid.SetRow(content_grid[content_grid.Count - 1], 1);
- Grid.SetColumn(content_grid[content_grid.Count - 1], 1);
- Grid.SetRowSpan(content_grid[content_grid.Count - 1], 1);
- Grid.SetColumnSpan(content_grid[content_grid.Count - 1], 1);
- // Add third column header
- button_grid.Add(button_button);
- button_grid[button_grid.Count - 1].Height = 82;
- button_grid[button_grid.Count - 1].Width = 188;
- button_grid[button_grid.Count - 1].Name = (button_grid.Count - 1).ToString();
- button_grid[button_grid.Count - 1].Visibility = Visibility.Visible;
- button_grid[button_grid.Count - 1].Content = "Læs Mere";
- button_grid[button_grid.Count - 1].FontSize = 22;
- button_grid[button_grid.Count - 1].Background = new SolidColorBrush(Colors.Black);
- button_grid[button_grid.Count - 1].Click += new RoutedEventHandler(send_i);
- button_grid[button_grid.Count - 1].VerticalAlignment = VerticalAlignment.Top;
- button_grid[button_grid.Count - 1].HorizontalAlignment = HorizontalAlignment.Left;
- button_grid[button_grid.Count - 1].Margin = new Thickness(0, create_grid_offset + 252, 0, 0);
- Grid.SetRow(button_grid[button_grid.Count - 1], 1);
- Grid.SetColumn(button_grid[button_grid.Count - 1], 1);
- Grid.SetRowSpan(button_grid[button_grid.Count - 1], 1);
- Grid.SetColumnSpan(button_grid[button_grid.Count - 1], 1);
- // Add column headers to the Grid
- tempgrid.Children.Add(overskrift_grid[overskrift_grid.Count - 1]);
- tempgrid.Children.Add(content_grid[content_grid.Count - 1]);
- tempgrid.Children.Add(image_grid[image_grid.Count - 1]);
- tempgrid.Children.Add(button_grid[button_grid.Count - 1]);
- news_grid.Add(tempgrid);
- news_grid[news_grid.Count - 1].Name = "dyn_" + (news_grid.Count -1).ToString();
- return news_grid[news_grid.Count - 1];
-
-
- // Navigate nav = new Navigate();
- // nav.Change_grid("nyheder", m);
- // Display grid into a Window
- }
- private void send_i(object sender, RoutedEventArgs e)
- {
-
- //Declare
- Button test = e.OriginalSource as Button;
- Control temp = test.Parent; //melder fejl på denne linje!
- MainPage m = new MainPage();
- Button src_button = e.OriginalSource as Button;
- int i = Convert.ToInt32(src_button.Name);
-
-
-
- if (if_declared.Contains(i))
- {
- // Switch to grid
-
- }
- else
- {
- // Create grid and then switch. + add to list
- Grid Grid_to_change = get_news_grid(i);
- temp.Visibility = Visibility.Visible;
- if_declared.Add(i);
- }
den melder fejl og siger:
"Cannot implicitly convert type 'System.Windows.DependencyObject' to 'System.Windows.Controls.Control'. An explicit conversion exists (are you missing a cast?)"
p.s er forholdsvis ny til C#
På forhånd tak for hjælpen