Bonjour, dans une solution WPF j'ai plusieurs projets WPF dont 2 vont nous intéresser :
1) Components
2) StoreAndKeep
Dans Components se trouvent des UserControls et notamment celui-ci :
il est ensuite utilisé dans une Page du dossier View de StoreAndSave comme ceci :
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
27 <UserControl x:Class="Components.Library.CtrListBox" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Components.Library" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="450" d:DesignWidth="800" mc:Ignorable="d"> <ListBox x:Name="LB" Width="{Binding ListBoxWidth}" Height="{Binding ListBoxHeight}" Margin="5" HorizontalAlignment="Left" VerticalAlignment="Top" Background="White" BorderBrush="{Binding ListBoxBorderBrush}" BorderThickness="3" DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:CtrListBox}}" IsEnabled="{Binding ListBoxEnabledState}" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" SelectedValue="{Binding ListBoxValue}" /> </UserControl>
Ensuite dans la partie code behind de cette vue j'ai besoin de faire référence à 'LB' qui est le x:name de ma listbox, comme ceci :
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
27
28
29
30
31
32
33
34
35 <Page x:Class="StoreAndKeep.View.DocumentsManagementView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:component="clr-namespace:Components.Library;assembly=Components" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vmodel="clr-namespace:StoreAndKeep.ViewModel" Title="DocumentsManagementView" d:DataContext="{d:DesignInstance Type=vmodel:DocumentsManagementViewModel}" d:DesignHeight="854" d:DesignWidth="1500" Background="{StaticResource Vs_Background}" mc:Ignorable="d"> <StackPanel> <!--#region Documents Temporaires--> <GroupBox Header="Fichiers Temporaires" Style="{StaticResource GroupBoxStyle}"> <StackPanel> <component:Ribbon x:Name="TemporaryFilesRibbon" ButtonDeleteVisibility="Visible" ButtonSelectVisibility="Visible" CmdButtonDelete="{Binding DeleteTemporaryFolderItemCmd}" CmdButtonSelect="{Binding GetSelectedTemporaryFileDetailsCmd}" /> <component:CtrListBox x:Name="TemporaryFolderItems" ListBoxBorderBrush="{StaticResource UiColor}" ListBoxHeight="150" ListBoxValue="{Binding TemporaryFilePath, UpdateSourceTrigger=PropertyChanged}" ListBoxWidth="600" /> </StackPanel> </GroupBox> <!--#endregion-->
Mais le mot 'LB' est souligné en rouge avec un erreur : 'CtrListBox.LB' est inaccessible en raison de son niveau de protection
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 public partial class DocumentsManagementView : Page { protected DocumentsManagementViewModel ViewModel { get; set; } public DocumentsManagementView() { InitializeComponent(); ViewModel = new DocumentsManagementViewModel(TemporaryFolderItems.LB); DataContext = ViewModel; } }
Que dois-je modifier dans mon code ??
Partager