Adding a checkbox to a repeater

A place for App developers to hang out / post
Post Reply
brianlich

Posts: 34
Joined: Wed Jun 08, 2011 1:49 am
Location:

HTPC Specs: Show details

Adding a checkbox to a repeater

#1

Post by brianlich » Wed Nov 13, 2013 5:11 am

I'm trying to figure out a way to have a checkbox next to a string in a repeater. Something similar to the Tasks -> Settings -> TV -> Guide -> Edit Channels page in Media Center.

I'm pulling in a list of strings from an ArrayDataList in C# into a repeater, which is working fine. Now I'd like to add the checkbox to the left of it, but I'm not sure how to do this.

Also, I have a Save button on the UI. When clicked, it would get the checked/not checked value of each checkbox and write it out to a file.

Any ideas?

sccrgoalie1

Posts: 317
Joined: Fri Jul 08, 2011 5:52 pm
Location:

HTPC Specs: Show details

#2

Post by sccrgoalie1 » Wed Nov 13, 2013 3:32 pm

brianlich wrote:I'm trying to figure out a way to have a checkbox next to a string in a repeater. Something similar to the Tasks -> Settings -> TV -> Guide -> Edit Channels page in Media Center.

I'm pulling in a list of strings from an ArrayDataList in C# into a repeater, which is working fine. Now I'd like to add the checkbox to the left of it, but I'm not sure how to do this.

Also, I have a Save button on the UI. When clicked, it would get the checked/not checked value of each checkbox and write it out to a file.

Any ideas?
It's relatively simple. You'll need to add an image that is an empty checkbox next to each string. Then in your arraydatalist you'll need to add objects of some class type you create which basically has two properties a string and a boolean checked value. In your MCML add conditions that check this boolean value and change the image to be either checked or unchecked based on this value. If you setup binding correctly the arraylistdata set will always have the checked/unchecked bool value when you click Save. Oh yeah, and when the image is clicked it should update that boolean value.

sccrgoalie1

Posts: 317
Joined: Fri Jul 08, 2011 5:52 pm
Location:

HTPC Specs: Show details

#3

Post by sccrgoalie1 » Wed Nov 13, 2013 3:39 pm

Here's an example of what I use. It's basically a checkbox with a channel logo and title next to it.

Here's how it's passed to the repeater

Code: Select all

 <Properties>
      <a:FavoriteSettings Name="FavoriteSettings"
                     FavoriteSettings="$Required"/>
</FavoriteSettings>
<Rules>
      <Binding Source ="[FavoriteSettings.FavoriteChannels]" Target ="[FavoritesRepeater.Source]"/>
</Rules>
 <Repeater Name="FavoritesRepeater">
                        <Layout>
                          <FlowLayout Spacing="0,0"
                                        Orientation="Vertical"/>
                        </Layout>
                        <Content>
                          <me:Channel FavoriteChannel="[RepeatedItem!a:FavoriteChannel]"/>
                        </Content>
                      </Repeater>
Here's the checkbox

Code: Select all

<UI Name ="Channel">
    <Properties>
      <a:FavoriteChannel Name="FavoriteChannel"
             FavoriteChannel="$Required"/>
    </Properties>
    <Locals>
      <KeyHandler Name="OKKey" Key="Enter" HandlerStage="Bubbled" />
      <KeyHandler Name="SpaceKey" Key="Space" HandlerStage="Bubbled" />
      <!-- React to "click" input. -->
      <ClickHandler Name="Clicker"/>

    </Locals>
    <Rules>
      <Binding Source ="[FavoriteChannel.ChannelName]" Target="[ChannelName.Content]"/>
      <Binding Source ="[FavoriteChannel.ChannelNumber]" Target="[ChannelNumber.Content]"/>
      <Condition Source ="[FavoriteChannel.IsFavorite]"
                  SourceValue ="true">
        <Conditions>
          <Equality Source ="[Input.MouseFocus]" Value ="false"/>
          <Equality Source ="[Input.KeyFocus]" Value ="false"/>
        </Conditions>
        <Actions>
          <Set Target ="[Checkbox.Content]" Value ="res://ehres!FIRSTRUN.CHECKBOX.CHECKED.NOFOCUS.PNG"/>
        </Actions>
      </Condition>
      <Condition Source ="[FavoriteChannel.IsFavorite]"
                  SourceValue ="false">
        <Conditions>
          <Equality Source ="[Input.MouseFocus]" Value ="false"/>
          <Equality Source ="[Input.KeyFocus]" Value ="false"/>
        </Conditions>
        <Actions>
          <Set Target ="[Checkbox.Content]" Value ="res://ehres!FIRSTRUN.CHECKBOX.UNCHECKED.NOFOCUS.PNG"/>
        </Actions>
      </Condition>
      <Condition Source="[Input.MouseFocus]"
                 SourceValue="true">
        <Conditions>
          <Equality Source ="[FavoriteChannel.IsFavorite]" Value ="true"/>
        </Conditions>
        <Actions>
          <Set Target ="[Checkbox.Content]" Value ="res://ehres!FIRSTRUN.CHECKBOX.CHECKED.FOCUS.PNG"/>
          <Set Target ="[ChannelNumber.Color]" Value ="color://s:GridItemTextColor"/>
          <Set Target ="[ChannelName.Color]" Value ="color://s:GridItemTextColor"/>
        </Actions>
      </Condition>
      <Condition Source="[Input.MouseFocus]"
                SourceValue="true">
        <Conditions>
          <Equality Source ="[FavoriteChannel.IsFavorite]" Value ="false"/>
        </Conditions>
        <Actions>
          <Set Target ="[Checkbox.Content]" Value ="res://ehres!FIRSTRUN.CHECKBOX.UNCHECKED.FOCUS.PNG"/>
          <Set Target ="[ChannelNumber.Color]" Value ="color://s:GridItemTextColor"/>
          <Set Target ="[ChannelName.Color]" Value ="color://s:GridItemTextColor"/>
        </Actions>
      </Condition>
      <Condition Source="[Input.KeyFocus]"
                 SourceValue="true">
        <Conditions>
          <Equality Source ="[FavoriteChannel.IsFavorite]" Value ="true"/>
        </Conditions>
        <Actions>
          <Set Target ="[Checkbox.Content]" Value ="res://ehres!FIRSTRUN.CHECKBOX.CHECKED.FOCUS.PNG"/>
          <Set Target ="[ChannelNumber.Color]" Value ="color://s:GridItemTextColor"/>
          <Set Target ="[ChannelName.Color]" Value ="color://s:GridItemTextColor"/>
        </Actions>
      </Condition>
      <Condition Source="[Input.KeyFocus]"
                SourceValue="true">
        <Conditions>
          <Equality Source ="[FavoriteChannel.IsFavorite]" Value ="false"/>
        </Conditions>
        <Actions>
          <Set Target ="[Checkbox.Content]" Value ="res://ehres!FIRSTRUN.CHECKBOX.UNCHECKED.FOCUS.PNG"/>
          <Set Target ="[ChannelNumber.Color]" Value ="color://s:GridItemTextColor"/>
          <Set Target ="[ChannelName.Color]" Value ="color://s:GridItemTextColor"/>
        </Actions>
      </Condition>
      <Condition Source="[FavoriteChannel.ChannelLogo]"
                      ConditionOp ="NotEquals"
                      SourceValue="null"
                      Target="[ChannelLogo.Content]"
                      Value="[FavoriteChannel.ChannelLogo]">
        <Actions>
          <Set Target ="[ChannelName.Visible]" Value ="false"/>
        </Actions>
      </Condition >
      <Condition Source="[FavoriteChannel.ChannelLogo]"
                     ConditionOp ="Equals"
                     SourceValue="null"
                  Target="[ChannelLogo.Visible]"
                      Value="false"/>

      <Changed Source="[Clicker.Invoked]">
        <Conditions>
          <Equality Source ="[FavoriteChannel.IsFavorite]" Value ="true"/>
        </Conditions>
        <Actions>
          <Set Target ="[FavoriteChannel.IsFavorite]" Value ="false"/>
        </Actions>
      </Changed>
      <Changed Source="[Clicker.Invoked]">
        <Conditions>
          <Equality Source ="[FavoriteChannel.IsFavorite]" Value ="false"/>
        </Conditions>
        <Actions>
          <Set Target ="[FavoriteChannel.IsFavorite]" Value ="true"/>
        </Actions>
      </Changed>
     
    </Rules>
    <Content>
      <Panel Layout ="HorizontalFlow"
             Margins="0,10,0,0">
        <Children>
          <Graphic Name ="Checkbox"/>
          <Text Name="ChannelNumber"
                Color="color://s:GridChannelNumberCellTextColor"
                Font="font://s:Segoe22"
                Margins="10,0,0,0" />
          <Graphic Name ="ChannelLogo"  
                   Margins="10,0,0,0" 
                   MaintainAspectRatio ="true"
                  
                   MaximumSize="100,50"/>          
          <Text Name="ChannelName"
                Color="color://s:GridChannelNumberCellTextColor"
                Font="font://s:Segoe22"
                Margins="10,0,0,0" />
        </Children>
      </Panel>
    </Content>
  </UI>
Here's the FavoriteChannel class

Code: Select all

 public class FavoriteChannel : ModelItem
    {
        public string ChannelId { get; set; }
        private string mChannelNumber;
        public string ChannelNumber
        {
            get
            {
                return mChannelNumber;
            }
            set
            {
                if (mChannelNumber != value)
                {
                    mChannelNumber = value;
                    FirePropertyChanged("ChannelNumber");
                }
            }
        }  
        private string mChannelName;
        public string ChannelName
        {
            get
            {
                return mChannelName;
            }
            set
            {
                if (mChannelName != value)
                {
                    mChannelName = value;
                    FirePropertyChanged("ChannelName");
                }
            }
        }  
        private bool mIsFavorite;
        public bool IsFavorite
        {
            get
            {
                return mIsFavorite;
            }
            set
            {
                if (mIsFavorite != value)
                {
                    mIsFavorite = value;
                    FirePropertyChanged("IsFavorite");
                }
            }
        }  
         private Image mChannelLogo;
         public Image ChannelLogo
         {
             get
             {
                 return mChannelLogo;
             }
             set
             {
                 if (mChannelLogo != value)
                 {
                     mChannelLogo = value;
                     FirePropertyChanged("ChannelLogo");
                 }
             }
         }

         public FavoriteChannel(string channelid,string channelname, string channelnumber, bool isFavorite, Image channellogo)
        {
            ChannelId = channelid;
            mChannelName = channelname;
            mChannelNumber = channelnumber;
            mIsFavorite = isFavorite;
            mChannelLogo = channellogo;
        }
        public FavoriteChannel()
        {
        }
    }
And lastly the FavoriteSettings class

Code: Select all

public class FavoriteSettings : ModelItem
    {
        private Log log;
        private AddInHost host;
        private XMLSettings settings;
        RemotePotato potato;
        private HistoryOrientedPageSession session;
        //public Microsoft.MediaCenter.UI.PropertyChangedEventHandler ApplicationContextPropertyChanged;
        Hashtable channels;


        public FavoriteSettings(Log l, XMLSettings s, HistoryOrientedPageSession ss, AddInHost hh, RemotePotato p)
        {
            log = l;
            settings = s;
            host = hh;
            session = ss;
            potato = p;
            try
            {
                channels = potato.AllTVChannels;
                mFavoriteChannels = new ArrayListDataSet();
                foreach (string channel in potato.channels)
                {
                    string channelname = ((TVService)channels[channel]).Callsign.ToString();
                    string displaychannelnumber = ((TVService)channels[channel]).MCChannelNumber.ToString();
                    bool isFavorite = ((TVService)channels[channel]).IsFavorite;
                    if (((TVService)channels[channel]).MCSubChannelNumber.ToString() != "" & ((TVService)channels[channel]).MCSubChannelNumber.ToString() != "0")
                    {
                        displaychannelnumber = displaychannelnumber + "." + ((TVService)channels[channel]).MCSubChannelNumber.ToString();
                    }
                    if (channels.ContainsKey(channel))
                    {
                        string channellogo = ((TVService)channels[channel]).LogoUri;
                        if (channellogo != null)
                        {
                            if (!File.Exists(new Uri(channellogo).LocalPath))
                            {
                                channellogo = "";
                            }
                        }
                        Image channelLogoImage;

                        if (channellogo == "" | channellogo == null)
                        {

                            channellogo = null;
                            channelLogoImage = null;
                        }
                        else
                        {
                            channelLogoImage = new Image(channellogo);
                        }
                        mFavoriteChannels.Add(new FavoriteChannel(channel,channelname, displaychannelnumber, isFavorite, channelLogoImage));
                    }
                }
                ////host.ApplicationContext.PropertyChanged += NavigateAway;
            }
            catch (Exception e)
            {
                log.writeLog(e.ToString(), LogInfoType.Error);
                DialogTest("Initialization failed");
                session.Close();
            }

        }
        public void Save()
        {
            try
            {
                bool overallSuccess = true;
                foreach (FavoriteChannel channel in FavoriteChannels)
                {
                    if (((TVService)channels[channel.ChannelId]).IsFavorite != channel.IsFavorite)
                    {
                        if (channel.IsFavorite)
                        {
                            if (potato.SetAsFavorite(channel.ChannelId) != "OK")
                            {
                                overallSuccess = false;
                            }
                        }
                        else
                        {
                            if (potato.UnsetAsFavorite(channel.ChannelId) != "OK")
                            {
                                overallSuccess = false;
                            }
                        }
                    }
                }
                if (!overallSuccess)
                {
                    DialogTest("One or more of the channels you changed may have not saved properly");
                }
                session.BackPage();
            }
            catch (Exception e)
            {
                log.writeLog(e.ToString(), LogInfoType.Error);
                DialogTest("Saving settings failed");
                session.Close();
            }
        }
        public void Cancel()
        {
            YesNoDialog("Are you sure you want to cancel without saving?");
        }
        public void Back()
        {
            YesNoDialog("Are you sure you want to exit without saving?");
        }

        public MediaCenterEnvironment MediaCenterEnvironment
        {
            get
            {
                if (host == null)
                    return null;
                return host.MediaCenterEnvironment;
            }
        }

        public void Close()
        {
            log.closeLog();
            host = null;
            session.Close();
        }

       
        public void DialogTest(string strClickedText)
        {
            int timeout = 5; bool modal = true; string caption = Resources.DialogCaption;
            if (session != null)
            {
                MediaCenterEnvironment.Dialog(strClickedText, caption, new object[] { DialogButtons.Ok }, timeout, modal, null, delegate(DialogResult dialogResult) { });
            }
            else
            {
                Debug.WriteLine("DialogTest");
            }
        }
        public void YesNoDialog(string strClickedText)
        {
            int timeout = 10; bool modal = true; string caption = Resources.DialogCaption;
            if (session != null)
            {
                DialogResult answer = MediaCenterEnvironment.Dialog(strClickedText, caption, new object[] { DialogButtons.Yes, DialogButtons.No }, timeout, modal, null, delegate(DialogResult dialogResult) { });
                if (answer == DialogResult.Yes)
                {
                    session.BackPage();
                }
            }
            else
            {
                Debug.WriteLine("DialogTest");
            }
        }

        #region "Properties"

        private ArrayListDataSet mFavoriteChannels;
        public ArrayListDataSet FavoriteChannels
        {
            get
            {
                return mFavoriteChannels;
            }
            set
            {
                if (mFavoriteChannels != value)
                {
                    mFavoriteChannels = value;
                    base.FirePropertyChanged("FavoriteChannels");
                }
            }
        }
With all that you should be able to figure out how it works, but let me know if you have questions.

brianlich

Posts: 34
Joined: Wed Jun 08, 2011 1:49 am
Location:

HTPC Specs: Show details

#4

Post by brianlich » Wed Nov 13, 2013 3:47 pm

Excellent. Thanks for the help! I'll give it a shot.

brianlich

Posts: 34
Joined: Wed Jun 08, 2011 1:49 am
Location:

HTPC Specs: Show details

#5

Post by brianlich » Tue Nov 19, 2013 4:26 am

Thanks for the awesome examples. It worked!
sccrgoalie1 wrote:Here's an example of what I use. It's basically a checkbox with a channel logo and title next to it.

Here's how it's passed to the repeater

Code: Select all

 <Properties>
      <a:FavoriteSettings Name="FavoriteSettings"
                     FavoriteSettings="$Required"/>
</FavoriteSettings>
<Rules>
      <Binding Source ="[FavoriteSettings.FavoriteChannels]" Target ="[FavoritesRepeater.Source]"/>
</Rules>
 <Repeater Name="FavoritesRepeater">
                        <Layout>
                          <FlowLayout Spacing="0,0"
                                        Orientation="Vertical"/>
                        </Layout>
                        <Content>
                          <me:Channel FavoriteChannel="[RepeatedItem!a:FavoriteChannel]"/>
                        </Content>
                      </Repeater>
Here's the checkbox

Code: Select all

<UI Name ="Channel">
    <Properties>
      <a:FavoriteChannel Name="FavoriteChannel"
             FavoriteChannel="$Required"/>
    </Properties>
    <Locals>
      <KeyHandler Name="OKKey" Key="Enter" HandlerStage="Bubbled" />
      <KeyHandler Name="SpaceKey" Key="Space" HandlerStage="Bubbled" />
      <!-- React to "click" input. -->
      <ClickHandler Name="Clicker"/>

    </Locals>
    <Rules>
      <Binding Source ="[FavoriteChannel.ChannelName]" Target="[ChannelName.Content]"/>
      <Binding Source ="[FavoriteChannel.ChannelNumber]" Target="[ChannelNumber.Content]"/>
      <Condition Source ="[FavoriteChannel.IsFavorite]"
                  SourceValue ="true">
        <Conditions>
          <Equality Source ="[Input.MouseFocus]" Value ="false"/>
          <Equality Source ="[Input.KeyFocus]" Value ="false"/>
        </Conditions>
        <Actions>
          <Set Target ="[Checkbox.Content]" Value ="res://ehres!FIRSTRUN.CHECKBOX.CHECKED.NOFOCUS.PNG"/>
        </Actions>
      </Condition>
      <Condition Source ="[FavoriteChannel.IsFavorite]"
                  SourceValue ="false">
        <Conditions>
          <Equality Source ="[Input.MouseFocus]" Value ="false"/>
          <Equality Source ="[Input.KeyFocus]" Value ="false"/>
        </Conditions>
        <Actions>
          <Set Target ="[Checkbox.Content]" Value ="res://ehres!FIRSTRUN.CHECKBOX.UNCHECKED.NOFOCUS.PNG"/>
        </Actions>
      </Condition>
      <Condition Source="[Input.MouseFocus]"
                 SourceValue="true">
        <Conditions>
          <Equality Source ="[FavoriteChannel.IsFavorite]" Value ="true"/>
        </Conditions>
        <Actions>
          <Set Target ="[Checkbox.Content]" Value ="res://ehres!FIRSTRUN.CHECKBOX.CHECKED.FOCUS.PNG"/>
          <Set Target ="[ChannelNumber.Color]" Value ="color://s:GridItemTextColor"/>
          <Set Target ="[ChannelName.Color]" Value ="color://s:GridItemTextColor"/>
        </Actions>
      </Condition>
      <Condition Source="[Input.MouseFocus]"
                SourceValue="true">
        <Conditions>
          <Equality Source ="[FavoriteChannel.IsFavorite]" Value ="false"/>
        </Conditions>
        <Actions>
          <Set Target ="[Checkbox.Content]" Value ="res://ehres!FIRSTRUN.CHECKBOX.UNCHECKED.FOCUS.PNG"/>
          <Set Target ="[ChannelNumber.Color]" Value ="color://s:GridItemTextColor"/>
          <Set Target ="[ChannelName.Color]" Value ="color://s:GridItemTextColor"/>
        </Actions>
      </Condition>
      <Condition Source="[Input.KeyFocus]"
                 SourceValue="true">
        <Conditions>
          <Equality Source ="[FavoriteChannel.IsFavorite]" Value ="true"/>
        </Conditions>
        <Actions>
          <Set Target ="[Checkbox.Content]" Value ="res://ehres!FIRSTRUN.CHECKBOX.CHECKED.FOCUS.PNG"/>
          <Set Target ="[ChannelNumber.Color]" Value ="color://s:GridItemTextColor"/>
          <Set Target ="[ChannelName.Color]" Value ="color://s:GridItemTextColor"/>
        </Actions>
      </Condition>
      <Condition Source="[Input.KeyFocus]"
                SourceValue="true">
        <Conditions>
          <Equality Source ="[FavoriteChannel.IsFavorite]" Value ="false"/>
        </Conditions>
        <Actions>
          <Set Target ="[Checkbox.Content]" Value ="res://ehres!FIRSTRUN.CHECKBOX.UNCHECKED.FOCUS.PNG"/>
          <Set Target ="[ChannelNumber.Color]" Value ="color://s:GridItemTextColor"/>
          <Set Target ="[ChannelName.Color]" Value ="color://s:GridItemTextColor"/>
        </Actions>
      </Condition>
      <Condition Source="[FavoriteChannel.ChannelLogo]"
                      ConditionOp ="NotEquals"
                      SourceValue="null"
                      Target="[ChannelLogo.Content]"
                      Value="[FavoriteChannel.ChannelLogo]">
        <Actions>
          <Set Target ="[ChannelName.Visible]" Value ="false"/>
        </Actions>
      </Condition >
      <Condition Source="[FavoriteChannel.ChannelLogo]"
                     ConditionOp ="Equals"
                     SourceValue="null"
                  Target="[ChannelLogo.Visible]"
                      Value="false"/>

      <Changed Source="[Clicker.Invoked]">
        <Conditions>
          <Equality Source ="[FavoriteChannel.IsFavorite]" Value ="true"/>
        </Conditions>
        <Actions>
          <Set Target ="[FavoriteChannel.IsFavorite]" Value ="false"/>
        </Actions>
      </Changed>
      <Changed Source="[Clicker.Invoked]">
        <Conditions>
          <Equality Source ="[FavoriteChannel.IsFavorite]" Value ="false"/>
        </Conditions>
        <Actions>
          <Set Target ="[FavoriteChannel.IsFavorite]" Value ="true"/>
        </Actions>
      </Changed>
     
    </Rules>
    <Content>
      <Panel Layout ="HorizontalFlow"
             Margins="0,10,0,0">
        <Children>
          <Graphic Name ="Checkbox"/>
          <Text Name="ChannelNumber"
                Color="color://s:GridChannelNumberCellTextColor"
                Font="font://s:Segoe22"
                Margins="10,0,0,0" />
          <Graphic Name ="ChannelLogo"  
                   Margins="10,0,0,0" 
                   MaintainAspectRatio ="true"
                  
                   MaximumSize="100,50"/>          
          <Text Name="ChannelName"
                Color="color://s:GridChannelNumberCellTextColor"
                Font="font://s:Segoe22"
                Margins="10,0,0,0" />
        </Children>
      </Panel>
    </Content>
  </UI>
Here's the FavoriteChannel class

Code: Select all

 public class FavoriteChannel : ModelItem
    {
        public string ChannelId { get; set; }
        private string mChannelNumber;
        public string ChannelNumber
        {
            get
            {
                return mChannelNumber;
            }
            set
            {
                if (mChannelNumber != value)
                {
                    mChannelNumber = value;
                    FirePropertyChanged("ChannelNumber");
                }
            }
        }  
        private string mChannelName;
        public string ChannelName
        {
            get
            {
                return mChannelName;
            }
            set
            {
                if (mChannelName != value)
                {
                    mChannelName = value;
                    FirePropertyChanged("ChannelName");
                }
            }
        }  
        private bool mIsFavorite;
        public bool IsFavorite
        {
            get
            {
                return mIsFavorite;
            }
            set
            {
                if (mIsFavorite != value)
                {
                    mIsFavorite = value;
                    FirePropertyChanged("IsFavorite");
                }
            }
        }  
         private Image mChannelLogo;
         public Image ChannelLogo
         {
             get
             {
                 return mChannelLogo;
             }
             set
             {
                 if (mChannelLogo != value)
                 {
                     mChannelLogo = value;
                     FirePropertyChanged("ChannelLogo");
                 }
             }
         }

         public FavoriteChannel(string channelid,string channelname, string channelnumber, bool isFavorite, Image channellogo)
        {
            ChannelId = channelid;
            mChannelName = channelname;
            mChannelNumber = channelnumber;
            mIsFavorite = isFavorite;
            mChannelLogo = channellogo;
        }
        public FavoriteChannel()
        {
        }
    }
And lastly the FavoriteSettings class

Code: Select all

public class FavoriteSettings : ModelItem
    {
        private Log log;
        private AddInHost host;
        private XMLSettings settings;
        RemotePotato potato;
        private HistoryOrientedPageSession session;
        //public Microsoft.MediaCenter.UI.PropertyChangedEventHandler ApplicationContextPropertyChanged;
        Hashtable channels;


        public FavoriteSettings(Log l, XMLSettings s, HistoryOrientedPageSession ss, AddInHost hh, RemotePotato p)
        {
            log = l;
            settings = s;
            host = hh;
            session = ss;
            potato = p;
            try
            {
                channels = potato.AllTVChannels;
                mFavoriteChannels = new ArrayListDataSet();
                foreach (string channel in potato.channels)
                {
                    string channelname = ((TVService)channels[channel]).Callsign.ToString();
                    string displaychannelnumber = ((TVService)channels[channel]).MCChannelNumber.ToString();
                    bool isFavorite = ((TVService)channels[channel]).IsFavorite;
                    if (((TVService)channels[channel]).MCSubChannelNumber.ToString() != "" & ((TVService)channels[channel]).MCSubChannelNumber.ToString() != "0")
                    {
                        displaychannelnumber = displaychannelnumber + "." + ((TVService)channels[channel]).MCSubChannelNumber.ToString();
                    }
                    if (channels.ContainsKey(channel))
                    {
                        string channellogo = ((TVService)channels[channel]).LogoUri;
                        if (channellogo != null)
                        {
                            if (!File.Exists(new Uri(channellogo).LocalPath))
                            {
                                channellogo = "";
                            }
                        }
                        Image channelLogoImage;

                        if (channellogo == "" | channellogo == null)
                        {

                            channellogo = null;
                            channelLogoImage = null;
                        }
                        else
                        {
                            channelLogoImage = new Image(channellogo);
                        }
                        mFavoriteChannels.Add(new FavoriteChannel(channel,channelname, displaychannelnumber, isFavorite, channelLogoImage));
                    }
                }
                ////host.ApplicationContext.PropertyChanged += NavigateAway;
            }
            catch (Exception e)
            {
                log.writeLog(e.ToString(), LogInfoType.Error);
                DialogTest("Initialization failed");
                session.Close();
            }

        }
        public void Save()
        {
            try
            {
                bool overallSuccess = true;
                foreach (FavoriteChannel channel in FavoriteChannels)
                {
                    if (((TVService)channels[channel.ChannelId]).IsFavorite != channel.IsFavorite)
                    {
                        if (channel.IsFavorite)
                        {
                            if (potato.SetAsFavorite(channel.ChannelId) != "OK")
                            {
                                overallSuccess = false;
                            }
                        }
                        else
                        {
                            if (potato.UnsetAsFavorite(channel.ChannelId) != "OK")
                            {
                                overallSuccess = false;
                            }
                        }
                    }
                }
                if (!overallSuccess)
                {
                    DialogTest("One or more of the channels you changed may have not saved properly");
                }
                session.BackPage();
            }
            catch (Exception e)
            {
                log.writeLog(e.ToString(), LogInfoType.Error);
                DialogTest("Saving settings failed");
                session.Close();
            }
        }
        public void Cancel()
        {
            YesNoDialog("Are you sure you want to cancel without saving?");
        }
        public void Back()
        {
            YesNoDialog("Are you sure you want to exit without saving?");
        }

        public MediaCenterEnvironment MediaCenterEnvironment
        {
            get
            {
                if (host == null)
                    return null;
                return host.MediaCenterEnvironment;
            }
        }

        public void Close()
        {
            log.closeLog();
            host = null;
            session.Close();
        }

       
        public void DialogTest(string strClickedText)
        {
            int timeout = 5; bool modal = true; string caption = Resources.DialogCaption;
            if (session != null)
            {
                MediaCenterEnvironment.Dialog(strClickedText, caption, new object[] { DialogButtons.Ok }, timeout, modal, null, delegate(DialogResult dialogResult) { });
            }
            else
            {
                Debug.WriteLine("DialogTest");
            }
        }
        public void YesNoDialog(string strClickedText)
        {
            int timeout = 10; bool modal = true; string caption = Resources.DialogCaption;
            if (session != null)
            {
                DialogResult answer = MediaCenterEnvironment.Dialog(strClickedText, caption, new object[] { DialogButtons.Yes, DialogButtons.No }, timeout, modal, null, delegate(DialogResult dialogResult) { });
                if (answer == DialogResult.Yes)
                {
                    session.BackPage();
                }
            }
            else
            {
                Debug.WriteLine("DialogTest");
            }
        }

        #region "Properties"

        private ArrayListDataSet mFavoriteChannels;
        public ArrayListDataSet FavoriteChannels
        {
            get
            {
                return mFavoriteChannels;
            }
            set
            {
                if (mFavoriteChannels != value)
                {
                    mFavoriteChannels = value;
                    base.FirePropertyChanged("FavoriteChannels");
                }
            }
        }
With all that you should be able to figure out how it works, but let me know if you have questions.

Post Reply