问题
In my application got one sidebar, which is holding this two component :
<Grid x:Name="AF" Visibility="Visibility">
<betata:AForm Height="508" VerticalAlignment="Top"/>
</Grid>
<Grid x:Name="AN" Visibility="Collapsed">
<betata:ANav Height="508" VerticalAlignment="Top"/>
</Grid>
in the AForm got hyperlink button with this method :
private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
{
Visibility = Visibility.Collapsed;
Sidebar sb = new Sidebar();
sb.AN.Visibility = Visibility.Visible;
}
but i not sure why the aForm will collapsed but AN could not become visible. or is there any other solution to implement ::
this line in main page to call up UC_A ::
<DWDS_LULCS_Views_Sidebar:Sidebar HorizontalAlignment="Left" Width="264"/>
- Main page holding
- User Control A (Sidebar) holding
- User Control B (admin login form) and
- User Control C (admin navigation menu)
UC_B default is visible, and click the button in UC_B to call UC_A's UC_C change the visibility to visible ?
回答1:
Finally this problem is being solve... i do in this way, make something in global variable for verification whether which to make visible and collapse, then give one event handler to sidebar (layout_updated). when i modify the visibility of UC_B, UC_A will being affected and the trigger will be call. lastly, the UC_A's layout_updated event will change the visibility of UC_C become visible.
回答2:
i do in this way, make something in global variable for verification whether which to make visible and collapse,
Another approach is to use an mvvm approach
<Border Background="Red" Visibility="{Binding HasChanges, Converter={StaticResource visibilityConverter}, FallbackValue=Collapsed}">
In your resources you will need to add
<local:BooleanToVisibilityConverter x:Key="visibilityConverter" OnTrue="Visible" OnFalse="Collapsed" />
You can then have a global object that you can set when your control's constructor after
InitializeComponent();
DataContext=new GlobalObjectKnownAsViewModel(); // are the source of Binding
This approach would be a good first start and later you can look at maybe using PRISM/mvvm light for additional behaviors and infrastructure they provide for mvvm work.
来源:https://stackoverflow.com/questions/7983939/visibility-of-user-control