-7

I've previously written several application in WPF, but I'm not sure how I should do this one:

I'm trying to make an "Universal App", designed toward the small screen on a raspberry Pi with win10 Iot.

I would like to create a usercontrol, which displays a value, and which when clicked expands to take up the full screen, allowing me to edit it nicely with some additional buttons (which show in the expanded version of the usercontrol)(e.g, numerical stepped Up/Down, + Ok/Cancel buttons). And when I click on the Ok Button in this expanded usercontrol, it should copy the EditedValue to the realValue (vars).

I'm a little stuck on how to do the part with a different display (different layouts, different components, taking all the place of the windows) and would like some help.

Max von Hippel
  • 2,856
  • 3
  • 29
  • 46
J4N
  • 19,480
  • 39
  • 187
  • 340
  • I would like to do something similar. Have you any thoughts on it? I personally would make a separate Edit page. – Alex H Jul 15 '15 at 10:39
  • @AlexH I would usually do this, but since it's a very generic value to edit, I would like to have it in several places – J4N Jul 15 '15 at 12:37
  • A Page with a Back Button should still do the trick. Are there any reasons not to use one? – Alex H Jul 15 '15 at 12:39
  • Well, I never did Windows Phone app, so maybe I'm not sure to know what it is. I'm putting this kind of reusable controls in a separate library, and I would like to be able to just drop it or not – J4N Jul 15 '15 at 17:47
  • 3
    You need to edit your question if you want any help. What have your tried, what isn't working, what code don't you understand? This should be a fairly simple solution. Google should have everything you need. – Kcvin Aug 06 '15 at 16:12
  • @NETscape: In fact I just don't know where to start, because I don't see how an user control(child) could decide to use all its parents size, and the goal is that the parent isn't really aware of that. – J4N Aug 07 '15 at 05:35
  • 4
    Start and learn by reading tutorials. Try something and come back, just get the basic functionality of showing values or something working. It'll be much easier for people to help if they have something to work with. No one is going to do it all for you. Read up on MVVM and start designing your apps properly. – Kcvin Aug 07 '15 at 14:27
  • @J4N on small screens many designers prefer not to have overly-nested menus because the UI topography (if you will) becomes confusing quickly. Thus according views help by giving the user visual context. – Max von Hippel Aug 07 '15 at 23:57

3 Answers3

0

Why not create a Usercontrol with a controltemplate that will change upon some property its template. A ControlTemplate with Triggers

Jordy van Eijk
  • 2,718
  • 2
  • 19
  • 37
0

What you are looking is an Accordian Control. These are easy to implement, but it can take a little bit of work to make then look/animate nicely. HERE is an open source project with an example and docs. This duplicate question (by which I mean yours is the duplicate, the other came first) also provides a variety of solutions.

Addressing the second component of your question- how to accommodate a small screen- there are several good design guidelines out there. You could look at the Apple Watch Human Interface Guidelines (that's certainly a small screen), or you could ask for recommendations in the UX/UI Stack Exchange.

Community
  • 1
  • 1
Max von Hippel
  • 2,856
  • 3
  • 29
  • 46
  • Thank you for your answer. I'm not sure that your answer is what I'm looking for, because here you just have a container that allow to focus on some items, in my case, the container could be a Grid/Dock which should be totally hided by one element – J4N Aug 08 '15 at 07:19
  • That is the definition of an accordion view. It is totally hidden until you click it, then it opens up to show stuff inside. Try looking at the links, or just google accordion view. – Max von Hippel Aug 08 '15 at 07:21
  • I did, but what I see, it's that this "accordeon" container always has an initial place, which isn't fully used, and may at some point use it fully. In my case, I want to have an usercontrol, which uses only 30% of the space, then use the full space. The goal is to have an UserControl in any view to have this behavior, not that the view has to be aware of this behavior every time. – J4N Aug 08 '15 at 16:22
0

@Jordy van Eijk provided you with a viable solution but since you asked for an example I will provide you with my own implementation. Please note there are plenty of variations and other ways you may do this, and as your question seems to be quite broad I will only fill in the initial design.

My approach uses the MVVM design pattern: A content presenter will bind to a view model and show the current data template. The data template will relate a view model to the user control. The user control contains your view, bindings to resize your selected item, and triggers to show/hide your extended display.

The Content Presenter (MainWindow.xaml):

<ContentPresenter Content="{Binding CurrentView}"/>

The Data Template (MainWindow.xaml):

<Window.Resources>
    <DataTemplate DataType="{x:Type viewModel:UserControl1ViewModel}" >
        <view:UserControl1/>
    </DataTemplate>
</Window.Resources>

The User Control (UserControl1.xaml):

<UserControl.Resources>
    <Style x:Key="ExtendedControl" TargetType="Button">
        <Setter Property="Visibility" Value="Collapsed"/>
        <Style.Triggers>
            <DataTrigger Binding="{Binding IsVisible}" Value="True">
                <Setter Property="Visibility" Value="Visible"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</UserControl.Resources>

<Grid HorizontalAlignment="Left" Background="Blue" Width="525">
    <Button Content="Resize Control" VerticalAlignment="Top" HorizontalAlignment="Left" Width="{Binding Width}" Height="265" Command="{Binding ResizeCommand}" Margin="10,30,0,0"/>
    <Button Content="Extended Control" Style="{StaticResource ExtendedControl}" Margin="383,32,25,258"/>
</Grid>

The User Control 1 View Model (UserControl1ViewModel.cs):

    public class UserControl1ViewModel : ViewModelBase
{
    public ICommand ResizeCommand
    {
        get
        {
            if (_resizeCommand == null) _resizeCommand = new RelayCommand(ResizeButton, () => true);
            return _resizeCommand;
        }
    }

    public bool IsVisible
    {
        get { return _isVisible; }
        set
        {
            _isVisible = value;
            RaisePropertyChanged("IsVisible");
        }
    }

    public double Width
    {
        get { return _width; }
        set
        {
            _width = value;
            RaisePropertyChanged("Width");
        }
    }

    private RelayCommand _resizeCommand;

    private bool _isVisible;

    private double _width;

    public UserControl1ViewModel()
    {
        Width = 100.0;
        IsVisible = false;
    }

    private void ResizeButton()
    {
        Width = Application.Current.MainWindow.ActualWidth * .65;
        IsVisible = true;
    }
}

Before Click:

Before Resize

After Click:

After Resize

This outlines the main pieces you will need to create a base application like you are specifying. When the resize control is pressed, its width binding is changed to expand its size to 65% of the application main window and the visibility binding of the extended control button is changed to true. Id include pictures of the resize but my reputation doesn't allow it just yet. I hope you look into MVVM as a future architectural pattern as others have suggested and if you have any further question beyond my simple overview feel free to contact me. Good Luck!

Edit: the classes for the base view model, commands, and binding properties come from the MVVM Light library. You can import this into your project from visual studio using: Tools -> NuGet Package Manager -> Manage NuGet Packages For Solution -> search for "MVVM Light"

Edit 2

For an example related to your comment. We have a parent grid containing an editor view that is always at 70 percent of max window size and a binding for our extended control panel size:

View:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="7*"/>
        <ColumnDefinition Width="{Binding Width}"/>
    </Grid.ColumnDefinitions>

    <ContentPresenter Content="{Binding ViewManager.EditorControlView}" Grid.Column="0"/>
    <ContentPresenter Content="{Binding ViewManager.ExtendedControlView}" Grid.Column="1"/>
</Grid>

Binding:

public string Width
{
    get { return _width; }

    set
    {
        _width = value;
        RaisePropertyChanged("Width")
    }
}

//set our extended control to the other 30 percent of the window size
Width = "3*";

To properly change this width adhering to MVVM standards, we need to use some form of communication between our view models and luckily that is another lesson you can pick up on from here. Just because iv used MVVM Light throughout this example id recommend searching google for "MVVM Light Messenger" as it provides a solid way of doing this communication. Using this you can just raise a change width to hide other window components in the parent view from anywhere in your application. :D

  • Ok I see, my concern here is: what if the parent of the owner is some grid with other components? I'm not sure to understand why it would takes the full parent place just because we set its width – J4N Aug 09 '15 at 08:51
  • @J4N Just added an edit two you can check out which explains what I believe you had described. – Dylan Ellington Aug 09 '15 at 13:14
  • Yes I see, But the goal is that the parent of this usercontrol would not have to know the behavior of its child(usercontrol). – J4N Aug 10 '15 at 05:00
  • @J4N If your parent has a grid, the child cannot properly share the window without it being aware of its parent. Using messaging this is a loosely coupled system where the parent wont rely on a child but just offers it that resizing capability at no cost if it isn't used. – Dylan Ellington Aug 10 '15 at 05:04
  • @J4N So my initial design had the user control doing all the work hiding and containing the extended view, while the edit two had them separated in two different user controls relying on some system like messaging to interact. This should give you an easy foundation to come up with whatever final design you need as both are versatile and can be mixed. – Dylan Ellington Aug 10 '15 at 05:09
  • @J4N also added pictures so you could see what the initial code was doing. – Dylan Ellington Aug 10 '15 at 05:40
  • I accept this answer since it's the closest to what I'm looking, even if at the end, what I was wishing to do doesn't seems possible. – J4N Aug 11 '15 at 17:38
  • @J4N I appreciate that I'm sorry I couldn't quite get you to where you needed to be. If you want to work more closely at some point or get an initial project going that I can look at I'll be happy to help then. Good luck and I wish you the best. – Dylan Ellington Aug 11 '15 at 18:09
  • I initially thought I could achieve such behavior by having some Grid with some fixed value and other mixed. My goal was NOT that, the goal was to make a usercontrol, that we can use in any container, without having to care that this specific has a specific behavior, for which we need to take care in size. The goal was more that it takes the size of the application and goes "above" everything else. I was not sure that it was possible, and seing the answers, it seems to confirm this. – J4N Aug 12 '15 at 07:09
  • @J4N that's where I set Application.Current.MainWindow."width or height@ so it'd dynamic – Dylan Ellington Aug 12 '15 at 07:17
  • Yes, but imagine that this usercontrol is put in a DockPanel, with some other childs, it will not be able to take the whole space, same thing if it's put in a Grid where some other row/column are fixed/auto – J4N Aug 12 '15 at 10:41
  • @J4N ohhhh I see! Well yes that's a dilemma. If the user put it in a non resizable container or didn't allow the user control to have access to the parent container, that it is their fault for incorrectly implementing it? I believe you have over complicated this "issue" and are trying to satisfy ever possible situation. Id go back and redefine my desired goals from this user control and write it accordingly even if it does contain all the possible cases you have thought of. To answer your last comment though, just assume that non resizable container is inside a resizable one haha – Dylan Ellington Aug 12 '15 at 12:20
  • This usercontrol is just to see what can be done. But my conception of the separation of concern, an usercontrol internal magic should not be known outside of this usercontrol – J4N Aug 13 '15 at 07:11