IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Presentation Foundation Discussion :

Afficher un canvas sous condition


Sujet :

Windows Presentation Foundation

  1. #1
    Membre averti
    Inscrit en
    Février 2005
    Messages
    12
    Détails du profil
    Informations forums :
    Inscription : Février 2005
    Messages : 12
    Par défaut Afficher un canvas sous condition
    Bonjour!

    Ayant déjà chercher sur le net, j espère que qqn pourra répondre à ma question!


    Voila j ai un label qui contient une une information.

    suivant l information je veux faire apparaître un canvas en-dessous de lui.

    est-ce possible? et comment?

    J ai déjà tout essayé mais rien n y fait! pourtant dans un autre fichier XAML je fait la même chose mais quand une comboBox change et la ça fonctionne!

  2. #2
    Membre émérite Avatar de jmix90
    Homme Profil pro
    Consultant .Net
    Inscrit en
    Juillet 2007
    Messages
    576
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Consultant .Net
    Secteur : Conseil

    Informations forums :
    Inscription : Juillet 2007
    Messages : 576
    Par défaut
    Bonjour,

    Tu souhaites que le canvas soit visible uniquement sous certaines conditions c'est cela ?

    Tu peux montrer le code que tu utilises, on pourra peut être y voir une erreur !

    ++

  3. #3
    Membre éclairé
    Inscrit en
    Novembre 2008
    Messages
    97
    Détails du profil
    Informations forums :
    Inscription : Novembre 2008
    Messages : 97
    Par défaut
    Salut,
    Voici une solution :

    1) Je crée une fenêtre nommée Window1 avec dans le xaml :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    <Window x:Class="TestCanvas.Window1"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:loc="clr-namespace:TestCanvas"
            Title="Window1" Height="300" Width="300">
     
        <Window.Resources>
            <loc:VisibilityConv x:Key="myVisibilityConv" />
        </Window.Resources>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="60"/>
                <RowDefinition/>
            </Grid.RowDefinitions>
     
            <Label Name="myLabel" Content="test"/>
     
            <Canvas Grid.Row="1" Visibility="{Binding ElementName=myLabel, Path=Content, Converter={StaticResource myVisibilityConv}}">
                <Rectangle Width="100" Height="50" Fill="Blue"/>
            </Canvas>
        </Grid>
    </Window>
    2) Je crée le converter :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Data;
    using System.Windows;
     
    namespace TestCanvas
    {
        public class VisibilityConv : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                string text = (string)value;
                if (text == "test")
                    return Visibility.Visible;
                else
                    return Visibility.Hidden;
            }
     
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                throw new NotImplementedException();
            }
        }
    }
    Quand j'exécute, le canvas apparait (on voit le rectangle bleu).
    Si je change le contenu de mon label myLabel, le canvas n'apparait plus.

  4. #4
    Membre extrêmement actif
    Inscrit en
    Avril 2008
    Messages
    2 573
    Détails du profil
    Informations personnelles :
    Âge : 65

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 573
    Par défaut
    bonjour july
    le code de Cecile5 qui est bon ,sauf que pour tester tout cela il faut executer .Or au run-time on ne voit pas on vas changer le content du label.
    pour tester cela voila le scenario:
    le content du label on va le binder sur un textbox,et en tapant dans le textbox :
    - affiche il affiche le canvas.
    - autrement il cache le canvas.
    voici ton code xaml revu:

    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
     
    <Window x:Class="TestCanvas.Window1"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:loc="clr-namespace:TestCanvas"
            Title="Window1" Height="300" Width="300">
     
        <Window.Resources>
            <loc:VisibilityConv x:Key="myVisibilityConv" />
        </Window.Resources>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="60"/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Canvas Grid.Row="1" Visibility="{Binding ElementName=monLabel, Path=Content, Converter={StaticResource myVisibilityConv}}" Background="WhiteSmoke">
                <Rectangle Width="92" Height="70" Fill="Blue" Canvas.Top="58" Canvas.Left="81" />
            </Canvas>
            <Label  Name="monLabel" Content="{Binding ElementName=monText, Path=Text}" HorizontalAlignment="Left" Width="117" Height="25" VerticalAlignment="Top" Background="AntiqueWhite" />
            <TextBox Name="monText" HorizontalAlignment="Right" Margin="0,0,14,0"  Width="120" VerticalAlignment="Top"
                   Text="kiki" Height="27.277" Background="Wheat" />
        </Grid>
    </Window>

    code behind:
    Code c# : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
     
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    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.Navigation;
    using System.Windows.Shapes;
     
    namespace TestCanvas
    {
        /// <summary>
        /// Logique d'interaction pour Window1.xaml
        /// </summary>
        public partial class Window1 : Window
        {
            public Window1()
            {
                InitializeComponent();
            }
        }
        public class VisibilityConv : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                string text = (string)value;
                if (text == "Affiche")
                    return Visibility.Visible;
                else
                    return Visibility.Hidden;
            }
     
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                throw new NotImplementedException();
            }
        }
    }
    bon code....

Discussions similaires

  1. Afficher un champs sous condition
    Par wachoo31 dans le forum IHM
    Réponses: 3
    Dernier message: 09/05/2007, 12h08
  2. Afficher un bloc sous condition
    Par taly dans le forum Général JavaScript
    Réponses: 10
    Dernier message: 19/09/2006, 11h25
  3. afficher un état sous condition
    Par remi59 dans le forum IHM
    Réponses: 4
    Dernier message: 15/09/2006, 16h24
  4. Afficher une image sous condition
    Par Chmog dans le forum BIRT
    Réponses: 5
    Dernier message: 28/07/2006, 12h11
  5. Afficher un champ sous condition
    Par Cantalou dans le forum Access
    Réponses: 24
    Dernier message: 01/02/2006, 14h25

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo