UWP-025 - Common XAML Controls - Part 2

Sign in to queue

The Discussion

  • User profile image
    mmckee

    Excellent videos! Thank you very much.

  • User profile image
    Amir

    Hi Bob
    tank you very much for your Excellent videos.
    I have a problem with AutoSuggestBox.
    In my string[] , My data start with capital letter .
    private string[] SteelSectionName = new string[] {"IPE 80","IPE 100","IPE 120","IPE 140", ...}
    when I type in AutoSuggestBox in small letter then can not found my Data automatic.i have to start my search word with Capital Letter.
    I want no different between them.

    private void SteelFindBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
    {
    var autoSteelFind = (AutoSuggestBox)sender;
    var filtered = SteelSectionName.Where(P => P.StartsWith(SteelFindBox.Text)).ToArray();
    SteelFindBox.ItemsSource = filtered;
    }

  • User profile image
    Paul1967

    Amir, what you can do is cast both the string you type and your SteelSectionName to lowercase (or uppercase). Change you filterd items code to:

    var filtered = SteelSectionName.Where(P => P.ToLower().StartsWith(SteelFindBox.Text.ToLower())).ToArray();

    ps. If you want to compare two strings for equality, ignoring case, you can use String.Compare(strA,strB,true)

  • User profile image
    BobTabor

    @Amir: Yeah, what @Paul1967 said.  :)

  • User profile image
    Amir

    Hi
    I used this code and worked for me . all Upper case and Lower case can search in my String Items:
    var filtered = SteelSectionName.Where(P => P.StartsWith((SteelFindBox.Text),StringComparison.CurrentCultureIgnoreCase)).ToArray();

  • User profile image
    dobardan

    @@Paul1967:how to add that code String.Compare(strA,strB,true) to work, im trying but i do not know how.

     

    Thank you@@Amir:for this line of code, it worked

    var filtered = SteelSectionName.Where(P => P.StartsWith((SteelFindBox.Text),StringComparison.CurrentCultureIgnoreCase)).ToArray()

    But i would like to know how to fix this this with  String.Compare(strA,strB,true)

    var filtered = SteelSectionName.Where(P => P.StartsWith((SteelFindBox.Text),StringComparison.CurrentCultureIgnoreCase)).ToArray()

  • User profile image
    Niner321107

    I have a question about CalendarDatePicker, will it adapt the control to the user system language?

  • User profile image
    Niner321107

    FYI: Margin="20" = Margin="20,20,20,20"

            Margin="X,Y"=Margin="X,Y,X,Y"

  • User profile image
    joeparis

    @BobTabor

    I think it might be helpful if you were to explain why you chose to cast sender, which is an AutoSuggestBox, to an AutoSuggestBox on line 48 of MainPage.xaml.cs. As far as I can see it was done only to make lines 49 & 50 (arguably) a little more readable. I rewrote your code as

    sender.ItemsSource = selectionItems.Where(p => p.StartsWith(sender.Text)).ToArray(); 

    which I understand might be daunting for an absolute beginner but I do think that explaining the difference between what you originally wrote and 

    var filtered = selectionItems.Where(p => p.StartsWith(sender.Text)).ToArray();
    sender.ItemsSource = filtered;
    

    would be immensely helpful.

    Along those lines I think it would also be helpful if you were to explain a bit about selectionItems as that seems more magical than any other piece of code.

    That being said, thank you so much(!) for this informative series. It's a fantastic beginner's guide!

  • User profile image
    paulos

    how come we have no control similar to NumericUpDown? Windows Forms have one. but WPF and UWP don't.

  • User profile image
    IS12

    I'm wondering how can we use the time from TimePicker control in our app?
    If a user chooses a certain time, can we get a variable we can use throughout our app? Like an alarm app, how would we know what time the user actually chose from the TimePicker?

    I managed to do something, but it only displays the already-selected time, it doesn't stay updated.

    {
    var time = MyTimePicker.Time;
    time.ToString() = DisplayChosenTimeTextBlock.Text;
    }

    Can we update "time" when the user changes something in the TimePicker control?

  • User profile image
    Mintydog

    I get a strange error on this line:

    var selectedDates = sender.SelectedDates.Select(p => p.Date.Month.ToString() + "/" + p.Date.Date.ToString()).ToArray();

    The error says "The type 'IBuffer' is defined in an assembly that is not reference. You must add a reference to assembly 'Windows. Version =255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'.

    I don't know what to do. I can't find help online other than one suggestion to reinstall VS. Does anybody know what to do?

    Thanks in advance.

    UPDATE:

    I've fixed it. maybe it was something to do with the way VS was install or updated, but I went to Add/Remove programs and clicked on my Visual Studio install > Modify > Repair

    After it repaired itself it worked fine.

  • User profile image
    Mintydog

    I've ran into a problem with the Menu flyout. With these lines

    <MenuFlyoutItem Text="Item 4" />
                            <MenuFlyoutSubItem Text="Item 5">
                                <MenuFlyoutItem Text="Item 6" />
                                <MenuFlyoutItem Text="Item 7" />
    For these lines intellisense is saying "Cannot add content to an object of type "MenuFlyoutSubitem"

    The design view is unable to display anything, however, the program actually works fine just like in the video, the flyout works as intended.

    Does anyone know what could be wrong? The full code for the Button and flyout is below. Thanks.

    <Button Grid.Row="4"
                    Margin="20,0,0,20"
                    Grid.Column="1"
                    Content="FlyoutMenu">
                <Button.Flyout>
                    <MenuFlyout Placement="Bottom">
                        <MenuFlyoutItem Text="Item 1" />
                        <MenuFlyoutItem Text="Item 2" />
                        <MenuFlyoutSeparator />
                        <MenuFlyoutSubItem Text="Item 3">
                            <MenuFlyoutItem Text="Item 4" />
                            <MenuFlyoutSubItem Text="Item 5">
                                <MenuFlyoutItem Text="Item 6" />
                                <MenuFlyoutItem Text="Item 7" />
                            </MenuFlyoutSubItem>
                        </MenuFlyoutSubItem>
                        <MenuFlyoutSeparator />
                        <ToggleMenuFlyoutItem Text="Item 8" />
                    </MenuFlyout>
                </Button.Flyout>
            </Button>

     Also the Auto Suggest box only works for me when the box is empty, then it brings up a list of every name.

  • User profile image
    Viktor

    The error is for when you try to add content in xaml to a control that isn't a ContentControl. It still works because for a MenuFlyoutSubItem, it just treats those items as its "Items" property.

    Like:
    <Button Grid.Row="4" Margin="20,0,0,20" Grid.Column="1" Content="FlyoutMenu">
    <Button.Flyout>
    <MenuFlyout Placement="Bottom">
    <MenuFlyoutItem Text="Item 1" />
    <MenuFlyoutItem Text="Item 2" />
    <MenuFlyoutSeparator />
    <MenuFlyoutSubItem Text="Item 3">
    <MenuFlyoutSubItem.Items>
    <MenuFlyoutItem Text="Item 4" />
    <MenuFlyoutSubItem Text="Item 5">
    <MenuFlyoutSubItem.Items>
    <MenuFlyoutItem Text="Item 6" />
    <MenuFlyoutItem Text="Item 7" />
    </MenuFlyoutSubItem.Items>
    </MenuFlyoutSubItem>
    </MenuFlyoutSubItem.Items>
    </MenuFlyoutSubItem>
    <MenuFlyoutSeparator />
    <ToggleMenuFlyoutItem Text="Item 8" />
    </MenuFlyout>
    </Button.Flyout>
    </Button>

  • User profile image
    Tolesy

    Hey Guys! Does any anyone knows how to Work around with the TIMEPICKER. To get selected items  to show on the textblock. Here are my code:

    private void MyTimePicker_TimeChanged(object sender, TimePickerValueChangedEventArgs e)
    {
    //TimePicker MyTimePicker = new TimePicker();
    var TimeSelected = sender.MyTimePicker.select(p => p.Time.Hour.ToString() + ":" + p.Time.Minute.ToString()).ToArray();
    var values = string.Join(",", TimeSelected);
    TimeViewResultTextBlock.Text = values;
    }

    Am having the red line under the Text highlighted in Bold. I also tried to call sender.Time.Select(p => p.Time.Hour.ToString() + ":" + p.Time.Minute.ToString()).ToArray(); But it didn't work too. How can we Update the Timepicker?  I went through this post and i saw IS12 was trying to figure out same thing.. Help Guys if you know how to.

  • User profile image
    Tolesy

    @IS12: Hi! Did you get this solved? i did something like this also but never worked:

    private void MyTimePicker_TimeChanged(object sender, TimePickerValueChangedEventArgs e)
    {

    var TimeSelected= sender.MyTimePicker.select(p => p.Time.Hour.ToString() + ":" + p.Time.Minute.ToString()).ToArray();
    var values = string.Join(",", TimeSelected);
    TimeViewResultTextBlock.Text = values;
    }

  • User profile image
    Tolesy

    @BobTabor: Before i read this comments below , i tried to fix what @Amir Question about seen both the string array in small and capital letter. I used this code :

     

    var lowerCase = from name in selectionItems Select(name.ToLower())

    foreach(var lw in lowerCase)

    {

    var autoSuggestBox = (AutoSuggestBox)sender;
    var filtered =lowerCase.Where(p => p.StartsWith(autoSuggestBox.Text)).ToArray();
    autoSuggestBox.ItemsSource = filtered;

    }

    This actually change all string array to small letters which was not what i wanted. Now i saw this var filtered = SteelSectionName.Where(P => P.ToLower().StartsWith(SteelFindBox.Text.ToLower())).ToArray(); from @paul 1967 , which i cant figure out straight why this code did what it has done in action. Can someone please Explain?

  • User profile image
    Tokan

    private void MyAutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
    {
    sender.ItemsSource = selectionItems.Where(P => P.StartsWith(sender.Text, StringComparison.CurrentCultureIgnoreCase));
    }

     This is the shortest solution.

  • User profile image
    tomaat69

    my AutoSuggestionBox functionality stopped after a few test runs. Also hitting arrow keys to navigate with the list seems to pick first on the list, not very useful if you try to select something else on the list, or am I doing something wrong here... I typed the code as in the lesson video.

Add Your 2 Cents