Vydělávej až 160.000 Kč měsíčně! Akreditované rekvalifikační kurzy s garancí práce od 0 Kč. Více informací.
Hledáme nové posily do ITnetwork týmu. Podívej se na volné pozice a přidej se do nejagilnější firmy na trhu - Více informací.
Avatar
asoft
Člen
Avatar
asoft:29.3.2015 11:32

Dobrý deň.
WPF, C#, Windows 8.1 64 bit, VS2013

Skúšam vytvoriť zdedený Form:

1. Najprv som urobil formulár MyWindow:

MyWindow.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Project_Test
{
    /// <summary>
    /// Interaction logic for MyWindow.xaml
    /// </summary>
    public partial class MyWindow : Window
    {
        public MyWindow()
        {
            InitializeComponent();
        }
    }
}

MyWindow.xaml

<Window x:Class="Project_Test.MyWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MyWindow" Height="300" Width="300">
    <Grid>
    </Grid>
</Window>

2. Teraz vytvorím zdedený Formulár: TestWindow z nadradeného formulára: MyWindow

TestWindow.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Project_Test
{
    /// <summary>
    /// Interaction logic for TestWindow.xaml
    /// </summary>
    public partial class TestWindow : MyWindow
    {
        public TestWindow()
        {
            InitializeComponent();
        }
    }
}

TestWindow.xaml

<src:MyWindow
  x:Class="Project_Test.TestWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:src="clr-namespace:Project_Test"
  Title="MyWindow" Height="300" Width="300">
    <Grid></Grid>
</src:MyWindow>

Na formulároch nie sú zatiaľ žiadne prvky - Controls.

Neviem sa zbaviť nasledovných hlášok:

Warning 1 'Project_Test­.TestWindow.I­nitializeCompo­nent()' hides inherited member 'Project_Test­.MyWindow.Ini­tializeComponen­t()'.
Use the new keyword if hiding was intended.
...Project_Tes­t\obj\Debug\Tes­tWindow.g.cs

Error 2 'Project_Test­.MyWindow' cannot be the root of a XAML file because it was defined using XAML.
Line 2 Position 3. ...Project_Tes­t\TestWindow.xaml

Editováno 29.3.2015 11:33
 
Odpovědět
29.3.2015 11:32
Avatar
Odpovídá na asoft
Michal Štěpánek:29.3.2015 12:02

Jaký účel má mít to dědění formuláře?

Nahoru Odpovědět
29.3.2015 12:02
Nikdy neříkej nahlas, že to nejde. Vždycky se totiž najde blbec, který to neví a udělá to...
Avatar
jiri.vytasil
Člen
Avatar
jiri.vytasil:29.3.2015 12:13

Pokud chces dedit XAMLy, tak to nejde.
Mezi XAMLy musi byt vzdy alespon jedno trida bez XAMLu.

Jde jen nasledujici:

MyWindow.xaml
class Base : MyWindow
TestWindow.xaml, ktery dedi z Base

 
Nahoru Odpovědět
29.3.2015 12:13
Avatar
asoft
Člen
Avatar
Odpovídá na jiri.vytasil
asoft:29.3.2015 19:18

A WfpControls sa dajú dediť bez obmedzenia ? (keďže sú to triedy bez xaml)
Napr:
public class MyTextBox1 : TextBox
public class MyTextBox2 : MyTextBox1
public class MyTextBox3 : MyTextBox2

 
Nahoru Odpovědět
29.3.2015 19:18
Avatar
jiri.vytasil
Člen
Avatar
Odpovídá na asoft
jiri.vytasil:29.3.2015 19:24

Jo,
ten priklad normalne jde a muzes MyTextBox3 pouzit v XAMLu.

Ono nejde jen dedit XAML od XAMLu, jinak dedit muzes.

Akceptované řešení
+20 Zkušeností
+2,50 Kč
Řešení problému
 
Nahoru Odpovědět
29.3.2015 19:24
Avatar
asoft
Člen
Avatar
Odpovídá na Michal Štěpánek
asoft:29.3.2015 19:27

Ide mi o to, že mám 10 formulárov, kde je základ ten istý.
Napr. je tam TabControl s 3 záložkami, 5 rovnakých textboxov a pod.
A potrebujem v prípade zmeny zmeniť iba ten formulár, z ktorého sa dedí, aby to zmenilo aj na ostatných formulároch.

 
Nahoru Odpovědět
29.3.2015 19:27
Avatar
jiri.vytasil
Člen
Avatar
Odpovídá na asoft
jiri.vytasil:29.3.2015 19:57

Pokud to mas takto, tak bych si vytvoril UserControl, ktery by mel v sobe to spolecne a tento UserControl pak vlozil do formulare.

<Window x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:bindingTest="clr-namespace:bindingTest"
        Title="MainWindow" Height="350" Width="525">
    <StackPanel>
        <TextBox Text=""/>
        <MyControl />

    </StackPanel>
</Window>

<UserControl x:Class="MyControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300">
    <StackPanel>
      <TextBox/>
      <TextBox/>
      <TextBox/>
      <TextBox/>
    </StackPanel>
</UserControl>

A mas ty textboxy definovane na jednom miste.

 
Nahoru Odpovědět
29.3.2015 19:57
Děláme co je v našich silách, aby byly zdejší diskuze co nejkvalitnější. Proto do nich také mohou přispívat pouze registrovaní členové. Pro zapojení do diskuze se přihlas. Pokud ještě nemáš účet, zaregistruj se, je to zdarma.

Zobrazeno 7 zpráv z 7.