Search Results

Search found 2796 results on 112 pages for 'switching desktops'.

Page 2/112 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • GPU hung when switching graphic card

    - by Lie Ryan
    I have a laptop (Dell Inspiron N4110) with a switchable graphic. $ lspci | grep VGA 00:02.0 VGA compatible controller: Intel Corporation 2nd Generation Core Processor Family Integrated Graphics Controller (rev 09) 01:00.0 VGA compatible controller: ATI Technologies Inc NI Whistler [AMD Radeon HD 6600M Series] (rev ff) Normally, my laptop starts with both graphic cards enabled, which caused the laptop to turn very hot and the fan to become very noisy. I have been using a small script to disable the Radeon card. For some time, I'm quite happy with this arrangement. However, I have been having some issues with the Intel card (IGD), the Intel card often randomly hang when running OpenGL apps; and so I want to give the Radeon card (DIS) another chance. I have never been able to switch to the Radeon card, but recently, I found out that if I do a "delayed switching" (DDIS): # echo "DDIS" > /sys/kernel/debug/vgaswitcheroo/switch root@lieryan-dell-ubuntu:/sys/kernel/debug/vgaswitcheroo# cat switch 0:IGD:+:Pwr:0000:00:02.0 1:DIS: :Pwr:0000:01:00.0 then I logoff (i.e. to restart X), the screen switch to pseudo-tty and then it stuck there freezing. At this situation, mouse and keyboard stops working so I can't switch to another ptty. I tried ssh-ing from another computer to salvage logs (dmesg at that point) and whatnot; I found out that when freezing, the active graphic card is the AMD card: -- this is from ssh -- # cat switch 0:IGD: :Off:0000:00:02.0 1:DIS:+:Pwr:0000:01:00.0 but the GPU is apparently hung, looking at dmesg gives: ... [ 1411.649974] vga_switcheroo: client 0 refused switch [ 1411.649985] vga_switcheroo: setting delayed switch to client 1 [ 1423.911759] vga_switcheroo: processing delayed switch to 1 [ 1424.006564] fbcon: Remapping primary device, fb1, to tty 1-63 [ 1424.006799] i915: switched off [ 1424.840351] [drm:drm_mode_getfb] *ERROR* invalid framebuffer id [ 1425.718088] [drm:drm_mode_getfb] *ERROR* invalid framebuffer id [ 1426.622377] [drm:drm_mode_getfb] *ERROR* invalid framebuffer id [ 1427.355683] [drm:drm_mode_getfb] *ERROR* invalid framebuffer id [ 1428.193549] [drm:drm_mode_getfb] *ERROR* invalid framebuffer id ... the invalid framebuffer id error is repeated for many times over ... I were able to successfully recover by switching back to the Intel card and restarting X from ssh; indicating that only the Radeon card has problems switching. System info: $ uname -a Linux lieryan-dell-ubuntu 3.0.0-14-generic #23-Ubuntu SMP Mon Nov 21 20:28:43 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 11.10 Release: 11.10 Codename: oneiric The laptop also do not have the option to set graphic card at BIOS and the proprietary driver, fglrx, also have never worked; when I installed it through jockey ("Additional Drivers"), glxinfo showed that it still being rendered by Mesa, the /sys/kernel/debug/vgaswitcheroo directory has gone missing, and the driver crashes with a traceback if I use xorg.conf to tell X to use fglrx. Anyone had any idea if it is possible to use this AMD card either with the radeon or the fglrx driver? logs: dmesg

    Read the article

  • Stateless layout switching in Ubuntu 14.04

    - by ulidtko
    I use extensively two keyboard layouts (latin for English, and cyrillic for Ukrainian and Russian), and it bothers me to experience my mode errors because of the additional bit of UI state: the current layout. I used to eliminate them completely by using stateless layout switching, whereby one has no next layout action (as such an action is based on the current state, which is easy to forget for the user, and so leads to errors), rather only two actions: enable latin layout; enable cyrillic layout. This was trivially accomplishable in pre-Saucy releases. As illustrated on the screenshot above. However, that settings window was destroyed in Saucy. How do I get my stateless switching now?

    Read the article

  • Tabs Visual Manager Adds Thumbnailed Tab Switching to Chrome

    - by ETC
    If you rock a bunch of tabs and sometimes need a little visual reminder to recall where you left a tab you’re looking for, Tabs Visual Manager thumbnails all your tabs for easy visual switching. Install Tabs Visual Manager, restart Chrome, and anytime you need to find a tab you can click on the Tabs Visual Manager icon in the toolbar. By default it opens a new tab with all your tab thumbnails, we found it was more convenient to switch it to pop-up mode (wherein it pops up a smaller menu from the icon itself instead of a whole new tab). Tabs Visual Manager is a free extension and works wherever Chrome does. Hit up the link below to read more and grab a copy. Tabs Visual Manager [Google Chrome Extensions] Latest Features How-To Geek ETC Should You Delete Windows 7 Service Pack Backup Files to Save Space? What Can Super Mario Teach Us About Graphics Technology? Windows 7 Service Pack 1 is Released: But Should You Install It? How To Make Hundreds of Complex Photo Edits in Seconds With Photoshop Actions How to Enable User-Specific Wireless Networks in Windows 7 How to Use Google Chrome as Your Default PDF Reader (the Easy Way) Reclaim Vertical UI Space by Moving Your Tabs to the Side in Firefox Wind and Water: Puzzle Battles – An Awesome Game for Linux and Windows How Star Wars Changed the World [Infographic] Tabs Visual Manager Adds Thumbnailed Tab Switching to Chrome Daisies and Rye Swaying in the Summer Wind Wallpaper Read On Phone Pushes Data from Your Desktop to the Appropriate Android App

    Read the article

  • Automatic switching between monitor configurations

    - by Michael Aquilina
    I have a laptop and an external monitor and i was wondering if there was a simple approach to switching between multiple monitor configurations based on the detected available displays. For example: When i am at home and i plug in my external monitor i would like this to automatically become enabled and the laptop screen to become disabled. As soon as i pull out the display cable for the external monitor, i would like the laptop screen to automatically become enabled. I was expecting this to just "work" just like it does in windows - but it seems to be much harder than that. I am aware of the xrandr command to turn displays on and off but i cannot seem to find a way to get this to work the way i describe above. I had also found this post about switching between multiple monitor configurations and the results seem a bit inconclusive. However i was hoping that with xrandr there would be a simpler solution. For me, the fact that when i pull out my external monitor the screen just goes black and i get an error message is a big issue holding me back from making the complete switch to linux as i move around alot as a student. My OS of choice is currently Kubuntu 12.04 but i am willing to change to something else if it provides a better way of setting up the described setup.

    Read the article

  • Workspace switching erroneously pins windows

    - by paniwani
    When switching from one workspace to the next using the Workspace switcher in the Launcher, I often see an orange square highlight, as if I am trying to pin a window to one side of the screen appear, although no window is even selected. Then after selecting a window, it is moved to the orange pinned position, which is frustrating. How do I fix this unwanted erroneous window pinning? I'm running Ubuntu 11.10. See screenshot:

    Read the article

  • How to Disable Application Switching in Windows 8

    - by Taylor Gibb
    Application switching allows you to quickly switch between your open Metro apps by sliding your finger across the left side of the screen, or moving your mouse to the corner. If you don’t like this behavior, it’s easy to disable. How to Stress Test the Hard Drives in Your PC or Server How To Customize Your Android Lock Screen with WidgetLocker The Best Free Portable Apps for Your Flash Drive Toolkit

    Read the article

  • VirtuaWin shows Visual Studio 2010 in all Desktops

    - by w0lf
    I'm using VirtuaWin in Windows 7 to have virtual desktop functionality and I think this program is awesome. There's one small issue, though: on the computer at work, when moving to another desktop it hides all windows in the current desktop, except any windows of Visual Studio 2010. This means that VS 2010 shows up in all desktops, while for all other windows, VirtuaWin applies the correct behavior. The strange thing is that this issue happens on one computer only; on the others I have it works OK. I have checked the Window Rules section and nothing seems strange in there. Is anyone else experiencing this kind of problem? Any ideas on how to solve it?

    Read the article

  • Is it possible to share a big-screen monitor - switching between personal Windows 7 laptop in the office?

    - by Nam Gi VU
    Hi everyone, This would be strange to ask this but I'll try a go :). The situation is as below. We use laptop & wifi in the office. We often make demo to each other and need to show the demo on a big screen mornitor hang in the middle of the room :). I want to switch the display between each of the staffs using LAN wifi network. Please give me some suggestions on how to do that. Thank you! Nam.

    Read the article

  • How to extend a window on 4 virtual desktops on Windows 7

    - by Patrice
    This site is very cool, and i often get many answers in it :) But today, I've a question for you. My Problem is: - I want to use a virtual desktop or resolution expander for windows 7 - I want to multiply per 2 a window resolution (i.e. seeing only 25% of one window on a screen) I tried simple tricks that didn't work for me, and installed a virtual desktop (Dexspot, a great one), but I can't manage to strech a window (Google chrome) over the 4 desktops simultaneously. Do you understand my problem, and have an answer to it? This would be great help ;-) See ya! Patrice

    Read the article

  • Best ways to move a server room and 80 desktops to a new building

    - by Marko
    Need to plan the best way to physically move a server room (12 IBM x3400 towers) and all associated networking equipment to a new building. Everything is going, comms (80 strong call centre operation), desktops(80-90) the whole lot and has to be done efficiently over a weekend. What I cant seem to find are the best ways to move equipment, i.e is it best to remove hard drives and pack them separetely, do I pack the chassis' with foam and/or surround them in bubble wrap? Are there specific products designed to move computer equipment and where would I find these. The internet has failed me so far, please help

    Read the article

  • Multiple desktops in Windows

    - by John Straka
    I'm running a program that uses WatiN to automate file uploads to different websites. I currently run it on a machine that I remote into via the standard Remote Desktop Connection in Windows - once I start an upload, I go ahead and continue using my local machine. Soon, I'll be needing to run it locally. The problem is that it requires focus (which is unavoidable due to WatiN utilizing SendKeys) and I of course don't want to render my machine useless while it runs. So, my question: Is there any way to emulate the multiple desktops/workspaces that have been in many Linux distros for some time? I tried VirtuaWin to no avail. Alternatively, is there a way to remote into a machine from itself? Or is there some other means of creating a separate session on the same machine that does not steal focus? Running Linux is not an option, and a VM would be overkill.

    Read the article

  • Alt-Tab in Unity 2D makes app icon jiggle instead of switching

    - by itsadok
    I'm using Unity 2D as my desktop, and it works fine most of the time, but every now and then, I try to Alt-Tab to switch to a different application, and instead of switching to that window, the launcher bar opens, and the icon of the application I was trying to switch to starts jiggling. If I try to switch to something else, that icon starts jiggling too. If I click on the icon with the mouse, then it stops jiggling and switches to the requested window. What is this behavior? I haven't seen any mention of jiggling icons in Unity. I don't understand the original purpose of this, and I'd like a way to fix it so that I won't have to use the mouse.

    Read the article

  • KVM switching from lower resolution system resets Ubuntu high resolution

    - by Ed Manet
    I'm running 12.04 desktop on my main desktop and it's hooked to a KVM (IOGear miniview) that shares the peripherals with a SLES 11 machine. The SLES 11 machine can't get the same resolution as the Ubuntu machine because of different graphics hardware. If I switch from Ubuntu to SLES and stay there too long, when I switch back to Ubuntu the screen resolution on Ubuntu is reset to the same as SLES. I can get it back easily just opening the Displays configuration; it immediately resets to the high resolution as soon as the Displays window opens. But all my open windows have been maximized and it's a P.I.T.A. having to resize them all again. How do I get it to just stay at the high resolution between switching between systems? Is there a setting in the Xorg conf file I need to set?

    Read the article

  • Simplifying ASP.NET Demos By Switching Web Server

    Starting with the DXperience v2010.1 release, our ASP.NET demos will no longer use the IIS web server. Instead, were switching to use the built-in ASP.NET Development Server (formerly known as Cassini web server). Why The Change? During the ASP.NET European training tour, we learned that many developers had issues with their IIS installations. While some were easy to fix and some were more, um, challenging, it's still a roadblock to appreciating our ASP.NET demos. The easiest fix is to use...Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here.

    Read the article

  • Gnome 3 freezes when switching workspaces

    - by Bill Cheatham
    I have found an odd problem with Gnome 3 on Ubuntu recently. Under certain circumstances, when switching between two workspaces the whole desktop and user interface will 'freeze' for anything up to 2 minutes; during this time I cannot click anything or interact using the keyboard. Often, the screen will show a 'half-completed' animation of the workspace swapper. This is on Ubuntu 12.04.1 running on a 2-year old Macbook Pro, and it only seems to occur when using an external monitor. This does not seem to be a processor or memory issue, and does not occur every time I switch workspaces. Is this a known problem? What can I do in the short or long term to fix it?

    Read the article

  • Clean installation of RHEL 5.5 claims package "desktops" is missing

    - by TKguru42
    Hi all, I'm a student worker in the CS department of my university, so please forgive me for any unprofessional descriptions. Simplified explanations are appreciated. I recently replaced some bad graphics cards in a few public workstations. The machines are all the same model. Before putting them back on the network I did fresh installs of RHEL---first I tried 5.4, but yum update ran into all sorts of ugly dependency errors and if I tried to remove any of the problematic packages, the whole operating system FUBAR'd. Using RHEL 5.5 gave me the same errors during install saying that "java.1.5.1-sun*" and "desktops" were missing, but yum update didn't have any dependency problems. Now that I tried logging in through the GUI, I encounter no GUI past the standard RHEL login page. The desktop is a uniform light teal and there's no system tray. An xclock window and an xterm window are open, and Firefox opens automatically, but that's it. Nothing else. What's REALLY confusing is that the computer claims that gnome is already installed, except it clearly isn't working. Any help or advice is greatly appreciated. If it helps, our department uses kickstart to run our standard Linux installs. I can try to get the script if that would be of use. Thank you!

    Read the article

  • Can't get virtual desktops to show up on RDWeb for Server 2012 R2

    - by Scott Chamberlain
    I built a test lab using the Windows Server 2012 R2 Preview. The initial test lab has the following configuration (I have replaced our name with "OurCompanyName" because I would like it if Google searches for our name did not cause people to come to this site, please do the same in any responses) Physical hardware running Windows Server 2012 R2 Preview full GUI, acting as Hyper-V host (joined to the test domain as testVwHost.testVw.OurCompanyName.com) with the following VM's running on it VM running 2012 R2 Core acting as domain controller for the forest testVw.OurCompanyName.com (testDC.testVw.OurCompanyName.com) VM running 2012 R2 Core with nothing running on it joined to the test domain as testIIS.testVw.OurCompanyName.com A clean install of Windows 7, all that was done to it was all windows updates where loaded and sysprep /generalize /oobe /shutdown /mode:vm was run on it A clean install of Windows 8, all that was done to it was all windows updates where loaded and sysprep /generalize /oobe /shutdown /mode:vm was run on it I then ran "Add Roles and Features" from testVwHost and chose the "Remote Desktop Services Installation", "Standard Deployment", "Virtual machine-based desktop deployment". I choose testIIS for the roles "RD Connection Broker" and "RD Web Access" and testVwHost as "RD Virtualization Host" The Install of the roles went fine, I then went to Remote Desktop Services in server manager and wet to setup Deployment Properties. I set the certificate for all 3 roles to our certificate signed by a CA for *.OurCompanyName.com. I then created a new Virtual Desktop Collection for Windows 7 and Windows 8 and both where created without issue. On the Windows 7 pool I added RemoteApp to launch WordPad, For windows 8 I did not add any RemoteApp programs. Everything now appears to be fine from a setup perspective however if I go to https://testIIS.testVw.OurCompanyName.com/RDWeb and log in as the use Administrator (or any orher user) I don't see the virtual desktops I created nor the RemoteApp publishing of WordPad. I tried adding a licensing server, using testDC as the server but that made no difference. What step did I miss in setting this up that is causing this not to show up on RDWeb? If any additional information is needed pleas let me know. I have tried every possible thing I can think of and I am just groping around in the dark now. The virtual machines running on testVwHost The configuration screen for RD Services The Windows 7 Pool The Windows 8 Pool This is logged in as testVw\Administrator

    Read the article

  • How to tell if leaving iOS app entered foreground from fast-app switching or manually?

    - by JPK
    Is there a way to tell if an iOS app enters the foreground from fast-app switching or manually? I need to know by the time applicationWillEnterForeground is called, so some specific code can be executed (or not executed) depending on the condition in which the app entered the foreground. EDIT: It turned out that this was more of a design issue for me. I moved my code to applicationDidBecomeActive. I also added a BOOL property to the appDelegate called fastAppSwitching (probably the wrong name for it). I set this to YES in application:handleOpenURL and application:openURL:sourceApplication:annotation. Then I added the following code to application:didFinishLaunchingWithOptions: if (launchOptions) { self.fastAppSwitching = YES; } else { self.fastAppSwitching = NO; } In applicationDidBecomeActive, I used the following code: if (fastAppSwitching == YES) { self.fastAppSwitching = NO; //stop, don't go any further } else { ... } EDIT2: MaxGabriel makes a good point below: "Just a warning to others taking the solution described here, applicationDidBecomeActive: is called when the user e.g. ignores a phone call or text message, unlike applicationWillEnterForeground". This is actually also true for in-app purchases and Facebook in-app authorization (new in iOS 6). So, with some further testing, this is the current solution: Add a new Bool called passedThroughWillEnterForeground. In applicationWillResignActive: self.passedThroughWillEnterForeground = NO; In applicationDidEnterBackground: self.passedThroughWillEnterForeground = NO; In applicationWillEnterForeground: self.passedThroughWillEnterForeground = YES; In applicationDidBecomeActive: if (passedThroughWillEnterForeground) { //we are NOT returning from 6.0 (in-app) authorization dialog or in-app purchase dialog, etc //do nothing with this BOOL - just reset it self.passedThroughWillEnterForeground = NO; } else { //we ARE returning from 6.0 (in-app) authorization dialog or in-app purchase dialog - IE //This is the same as fast-app switching in our book, so let's keep it simple and use this to set that self.fastAppSwitching = YES; } if (fastAppSwitching == YES) { self.fastAppSwitching = NO; } else { ... } EDIT3: I think we also need a bool to tell if app was launched from terminated.

    Read the article

  • Switching to workspaces view shows buggy blue background

    - by G1i1ch
    When switching to workspaces view everything the background turns blue. Same happens when I switch between multiple windows of the same app too. Happening after having a try with gnome shell out of curiosity. Installed through official repos like normal. Tried it out but switched back, anyone have an idea of why this is happening? Got an Intel GPU and Unity 3d. If anyone can give me some direction, thanks a lot. Update: Looks like during the switch somehow opengl was disabled. glxinfo returns: name of display: :0 Xlib: extension "GLX" missing on display ":0". Xlib: extension "GLX" missing on display ":0". Xlib: extension "GLX" missing on display ":0". Xlib: extension "GLX" missing on display ":0". Xlib: extension "GLX" missing on display ":0". Error: couldn't find RGB GLX visual or fbconfig Xlib: extension "GLX" missing on display ":0". Xlib: extension "GLX" missing on display ":0". Xlib: extension "GLX" missing on display ":0". Xlib: extension "GLX" missing on display ":0". Xlib: extension "GLX" missing on display ":0". Xlib: extension "GLX" missing on display ":0". Xlib: extension "GLX" missing on display ":0". This is very distressing, all I wanted to do was try out gnome3. Does anyone have an idea on how I can get opengl back? [update] Ok I found out what happened. Apparently it's not that hard to accidentally install an nvidia driver. All I had to do was remove all the stuff that had nvidia in it and I got 3d back! For anyone else, this is how I found out: check out Xorg.0.log `$ cat / var/log/Xorg.0.log | more` if you see a line like this somewhere `(EE) Failed to initialize GLX extension (Compatible NVIDIA X driver not found)` you got an nvidia problem Thanks everyone for trying to help :D

    Read the article

  • Switching mdadm to an external bitmap

    - by Oli
    I've just read this in another post about improving RAID5/6 write speeds: After increasing stripe cache & switching to external bitmap, my speeds are 160 Mb/s writes, 260 Mb/s reads. :-D I've already found out how to increase the stripe cache and this worked pretty well but I'd like to know more about an external bitmap. I have an incredibly fast (540MB/s) RAID0 SSD that would do well if a bitmap does what I think it does but I'm still very unsure. I've only known about them as long as I've known this post. A few questions: What is a bitmap (in terms of mdadm)? What are the advantages of an internal bitmap (over external)? What are the advantages of an external bitmap (over internal)? How do I switch between the two? I should add that while this is a I'm-bored-let's-break-something thread, I do value the data stored on the RAID array. If doing this is going to put data at significant risk, please let me know.

    Read the article

  • Dualboot (Win 8 / Ubuntu 13) is stuck at 'switching to clocksource'

    - by Daniel Puscht
    for days I have been crawling the web for solutions to my problem, but couln't find any. Here it is: I got a new Laptop (ASUS Vivobook S200E) with Win 8 OEM preinstalled. I wanted to create a dual-boot system with Ubuntu 13 next to it. I read about UEFI and that I have to turn of Secure Boot and use the existing EFI partition as bootloader for Ubuntu. So I did. I also ran boot-repair reinstalling the GRUB. The result is when I start the computer I get into the boot menu. So far, so good. When I pick Win everthing is fine. But when I choose Ubuntu (recovery) the system starts, but gets stuck at the line '[1.806366] Switching to clocksource tsc'. I already tried other versions of Ubuntu (12.04.2, 12.10). I played with boot-repair (using the recommended fix, setting everything manually). But nothing works. It's always the same issue. I read that it could be a problem concerning graphic drivers, but this I can hardly believe. If this is any help, boot-repair gave me this link to post in fora. http://paste.ubuntu.com/5810391/ Thanks for any help in advance

    Read the article

  • Switching To Ubuntu 14.04 from Windows 8.1

    - by Asangam
    everyone i am newto these linux stuffs. Currently i'm a user of Windows8.1 . When windows 8 was roling out i was like i'm never going to leave and will be always stick to windows8 but now i think it's time to switch linux because being in windows forever i don't think i can do something very good .I wanted to be OpenSource :) . So i really dont have any idea about linux . For me the best distro is Ubuntu and Kubuntu offcourse the latest release . So what i'm afraid of switching to linux is its compability .The compatibility i'm talking about is with the hardware's and driver's . For eg sometime after fresh install of windows we need to install the display,usb and wifi drivers to function . For some computer or brands those driver's are hard to find and i can't even think of linux how hard are they to find if it needs installing drivers. So my main question is that do i need to install the drivers for my wifi adapters display and some other stuffs or the distro i choosed i.e Ubuntu 14.0.4 consists of those dirvers and what about the 64 and 32bit . My machines is 64bit aso do i need to install the 64bit one . I mean i know the advantages of installing the 64 bit one but like windows is it kinda hard to find softwares for the 64 bit one . Or the 32 bit is recommended . And Yes I will be highly appreciated for the answers to my questions . Thank You :)

    Read the article

  • Sync active wallpaper/background between KDE and Gnome/Unity

    - by Ike
    Is there solution using a utility or folder shortcuts that would keep the active desktop wallpaper/background the same in KDE and Gnome/Unity. (Changing the background in one desktop would also change the other desktop's wallpaper) I use both desktops because they both serve me better for different tasks, and i'd like to match LightDM login background for KDE as well. Regardless of that it would just be nice to accomplish this for personal consistency and unity. This is no heart breaker if it's not possible. It's just an extra couple of steps when I want to change my background. note: in KDE I disable ksplash

    Read the article

  • Have you tried to switch to different kind of language and find a job in a "new language" ?

    - by IAdapter
    I'm a Java programmer(J2EE/JEE), but I'm thinking about switching to C#. Does any of you have been in my position and have switched from Java to C# or C# to Java or C++ to Java, etc. ?? I'm NOT asking about switching between the same kind of languages, for example Java to Groovy/Scala/JRuby, C++ to C, VB to C#, C# to IronRuby/F#/VB.NET. Or if you company was C++, but has moved to Java(you had no choice and I'm about to make a choice). Side question: How hard was it to get a job in a "new language"?

    Read the article

  • Metro: Dynamically Switching Templates with a WinJS ListView

    - by Stephen.Walther
    Imagine that you want to display a list of products using the WinJS ListView control. Imagine, furthermore, that you want to use different templates to display different products. In particular, when a product is on sale, you want to display the product using a special “On Sale” template. In this blog entry, I explain how you can switch templates dynamically when displaying items with a ListView control. In other words, you learn how to use more than one template when displaying items with a ListView control. Creating the Data Source Let’s start by creating the data source for the ListView. Nothing special here – our data source is a list of products. Two of the products, Oranges and Apples, are on sale. (function () { "use strict"; var products = new WinJS.Binding.List([ { name: "Milk", price: 2.44 }, { name: "Oranges", price: 1.99, onSale: true }, { name: "Wine", price: 8.55 }, { name: "Apples", price: 2.44, onSale: true }, { name: "Steak", price: 1.99 }, { name: "Eggs", price: 2.44 }, { name: "Mushrooms", price: 1.99 }, { name: "Yogurt", price: 2.44 }, { name: "Soup", price: 1.99 }, { name: "Cereal", price: 2.44 }, { name: "Pepsi", price: 1.99 } ]); WinJS.Namespace.define("ListViewDemos", { products: products }); })(); The file above is saved with the name products.js and referenced by the default.html page described below. Declaring the Templates and ListView Control Next, we need to declare the ListView control and the two Template controls which we will use to display template items. The markup below appears in the default.html file: <!-- Templates --> <div id="productItemTemplate" data-win-control="WinJS.Binding.Template"> <div class="product"> <span data-win-bind="innerText:name"></span> <span data-win-bind="innerText:price"></span> </div> </div> <div id="productOnSaleTemplate" data-win-control="WinJS.Binding.Template"> <div class="product onSale"> <span data-win-bind="innerText:name"></span> <span data-win-bind="innerText:price"></span> (On Sale!) </div> </div> <!-- ListView --> <div id="productsListView" data-win-control="WinJS.UI.ListView" data-win-options="{ itemDataSource: ListViewDemos.products.dataSource, layout: { type: WinJS.UI.ListLayout } }"> </div> In the markup above, two Template controls are declared. The first template is used when rendering a normal product and the second template is used when rendering a product which is on sale. The second template, unlike the first template, includes the text “(On Sale!)”. The ListView control is bound to the data source which we created in the previous section. The ListView itemDataSource property is set to the value ListViewDemos.products.dataSource. Notice that we do not set the ListView itemTemplate property. We set this property in the default.js file. Switching Between Templates All of the magic happens in the default.js file. The default.js file contains the JavaScript code used to switch templates dynamically. Here’s the entire contents of the default.js file: (function () { "use strict"; var app = WinJS.Application; app.onactivated = function (eventObject) { if (eventObject.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) { WinJS.UI.processAll().then(function () { var productsListView = document.getElementById("productsListView"); productsListView.winControl.itemTemplate = itemTemplateFunction; });; } }; function itemTemplateFunction(itemPromise) { return itemPromise.then(function (item) { // Select either normal product template or on sale template var itemTemplate = document.getElementById("productItemTemplate"); if (item.data.onSale) { itemTemplate = document.getElementById("productOnSaleTemplate"); }; // Render selected template to DIV container var container = document.createElement("div"); itemTemplate.winControl.render(item.data, container); return container; }); } app.start(); })(); In the code above, a function is assigned to the ListView itemTemplate property with the following line of code: productsListView.winControl.itemTemplate = itemTemplateFunction;   The itemTemplateFunction returns a DOM element which is used for the template item. Depending on the value of the product onSale property, the DOM element is generated from either the productItemTemplate or the productOnSaleTemplate template. Using Binding Converters instead of Multiple Templates In the previous sections, I explained how you can use different templates to render normal products and on sale products. There is an alternative approach to displaying different markup for normal products and on sale products. Instead of creating two templates, you can create a single template which contains separate DIV elements for a normal product and an on sale product. The following default.html file contains a single item template and a ListView control bound to the template. <!-- Template --> <div id="productItemTemplate" data-win-control="WinJS.Binding.Template"> <div class="product" data-win-bind="style.display: onSale ListViewDemos.displayNormalProduct"> <span data-win-bind="innerText:name"></span> <span data-win-bind="innerText:price"></span> </div> <div class="product onSale" data-win-bind="style.display: onSale ListViewDemos.displayOnSaleProduct"> <span data-win-bind="innerText:name"></span> <span data-win-bind="innerText:price"></span> (On Sale!) </div> </div> <!-- ListView --> <div id="productsListView" data-win-control="WinJS.UI.ListView" data-win-options="{ itemDataSource: ListViewDemos.products.dataSource, itemTemplate: select('#productItemTemplate'), layout: { type: WinJS.UI.ListLayout } }"> </div> The first DIV element is used to render a normal product: <div class="product" data-win-bind="style.display: onSale ListViewDemos.displayNormalProduct"> <span data-win-bind="innerText:name"></span> <span data-win-bind="innerText:price"></span> </div> The second DIV element is used to render an “on sale” product: <div class="product onSale" data-win-bind="style.display: onSale ListViewDemos.displayOnSaleProduct"> <span data-win-bind="innerText:name"></span> <span data-win-bind="innerText:price"></span> (On Sale!) </div> Notice that both templates include a data-win-bind attribute. These data-win-bind attributes are used to show the “normal” template when a product is not on sale and show the “on sale” template when a product is on sale. These attributes set the Cascading Style Sheet display attribute to either “none” or “block”. The data-win-bind attributes take advantage of binding converters. The binding converters are defined in the default.js file: (function () { "use strict"; var app = WinJS.Application; app.onactivated = function (eventObject) { if (eventObject.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) { WinJS.UI.processAll(); } }; WinJS.Namespace.define("ListViewDemos", { displayNormalProduct: WinJS.Binding.converter(function (onSale) { return onSale ? "none" : "block"; }), displayOnSaleProduct: WinJS.Binding.converter(function (onSale) { return onSale ? "block" : "none"; }) }); app.start(); })(); The ListViewDemos.displayNormalProduct binding converter converts the value true or false to the value “none” or “block”. The ListViewDemos.displayOnSaleProduct binding converter does the opposite; it converts the value true or false to the value “block” or “none” (Sadly, you cannot simply place a NOT operator before the onSale property in the binding expression – you need to create both converters). The end result is that you can display different markup depending on the value of the product onSale property. Either the contents of the first or second DIV element are displayed: Summary In this blog entry, I’ve explored two approaches to displaying different markup in a ListView depending on the value of a data item property. The bulk of this blog entry was devoted to explaining how you can assign a function to the ListView itemTemplate property which returns different templates. We created both a productItemTemplate and productOnSaleTemplate and displayed both templates with the same ListView control. We also discussed how you can create a single template and display different markup by using binding converters. The binding converters are used to set a DIV element’s display property to either “none” or “block”. We created a binding converter which displays normal products and a binding converter which displays “on sale” products.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >